From 8c04bed572ea21d64790a4e048487639f654870c Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 24 Jun 2017 21:12:15 +0300 Subject: [PATCH] Display empty event log placeholder. Also hide the filter button for now. --- Telegram/Resources/langs/lang.strings | 2 +- Telegram/SourceFiles/history/history.style | 3 ++ .../history/history_admin_log_inner.cpp | 36 +++++++++++++------ .../history/history_admin_log_inner.h | 2 ++ .../history/history_admin_log_section.cpp | 4 ++- .../history/history_media_types.cpp | 4 +-- Telegram/SourceFiles/lang/lang_tag.cpp | 4 +-- 7 files changed, 39 insertions(+), 16 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index a7dc4bfae..bed14d0b8 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1321,7 +1321,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org "lng_admin_log_no_results_title" = "No events found"; "lng_admin_log_no_results_text" = "No recent events that match your query have been found."; "lng_admin_log_no_events_title" = "No events yet"; -"lng_admin_log_no_events_text" = "There were no service actions taken by the group's members and admins in the last 48 hours."; +"lng_admin_log_no_events_text" = "There were no service actions\ntaken by the group's members\nand admins in the last 48 hours."; "lng_admin_log_empty_text" = "Empty"; "lng_admin_log_changed_title_group" = "{from} changed group name to «{title}»"; diff --git a/Telegram/SourceFiles/history/history.style b/Telegram/SourceFiles/history/history.style index 6a54b62ab..32a73ca4c 100644 --- a/Telegram/SourceFiles/history/history.style +++ b/Telegram/SourceFiles/history/history.style @@ -445,3 +445,6 @@ historyVideoMessageMute: icon {{ "volume_mute", historyFileThumbIconFg }}; historyVideoMessageMuteSelected: icon {{ "volume_mute", historyFileThumbIconFgSelected }}; historyVideoMessageMuteSize: 25px; historyVideoMessageProgressOpacity: 0.72; + +historyAdminLogEmptyWidth: 260px; +historyAdminLogEmptyPadding: margins(10px, 12px, 10px, 12px); diff --git a/Telegram/SourceFiles/history/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/history_admin_log_inner.cpp index d38b33e60..0e9436261 100644 --- a/Telegram/SourceFiles/history/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/history_admin_log_inner.cpp @@ -38,7 +38,8 @@ namespace AdminLog { namespace { constexpr auto kScrollDateHideTimeout = 1000; -constexpr auto kEventsPerPage = 1; +constexpr auto kEventsFirstPage = 20; +constexpr auto kEventsPerPage = 50; } // namespace @@ -203,7 +204,8 @@ InnerWidget::InnerWidget(QWidget *parent, gsl::not_null con , _channel(channel) , _history(App::history(channel)) , _scrollTo(std::move(scrollTo)) -, _scrollDateCheck([this] { scrollDateCheck(); }) { +, _scrollDateCheck([this] { scrollDateCheck(); }) +, _emptyText(st::historyAdminLogEmptyWidth - st::historyAdminLogEmptyPadding.left() - st::historyAdminLogEmptyPadding.left()) { setMouseTracking(true); _scrollDateHideTimer.setCallback([this] { scrollDateHideByTimer(); }); subscribe(AuthSession::Current().data().repaintLogEntry(), [this](gsl::not_null historyItem) { @@ -221,6 +223,7 @@ InnerWidget::InnerWidget(QWidget *parent, gsl::not_null con *query.isVisible = true; } }); + updateEmptyText(); } void InnerWidget::setVisibleTopBottom(int visibleTop, int visibleBottom) { @@ -311,6 +314,17 @@ void InnerWidget::checkPreloadMore() { void InnerWidget::applyFilter(MTPDchannelAdminLogEventsFilter::Flags flags, const std::vector> &admins) { _filterFlags = flags; _filterAdmins = admins; + updateEmptyText(); +} + +void InnerWidget::updateEmptyText() { + auto options = _defaultOptions; + options.flags |= TextParseMono; // For italic :/ + auto hasFilter = (_filterFlags != 0) || !_filterAdmins.empty(); + auto text = TextWithEntities { lang(hasFilter ? lng_admin_log_no_results_title : lng_admin_log_no_events_title) }; + text.entities.append(EntityInText(EntityInTextBold, 0, text.text.size())); + text.text.append(qstr("\n\n") + lang(hasFilter ? lng_admin_log_no_results_text : lng_admin_log_no_events_text)); + _emptyText.setMarkedText(st::defaultTextStyle, text, options); } QString InnerWidget::tooltipText() const { @@ -374,7 +388,8 @@ void InnerWidget::preloadMore(Direction direction) { auto query = QString(); auto maxId = (direction == Direction::Up) ? _minId : 0; auto minId = (direction == Direction::Up) ? 0 : _maxId; - requestId = request(MTPchannels_GetAdminLog(MTP_flags(flags), _channel->inputChannel, MTP_string(query), filter, MTP_vector(admins), MTP_long(maxId), MTP_long(minId), MTP_int(kEventsPerPage))).done([this, &requestId, &loadedFlag, direction](const MTPchannels_AdminLogResults &result) { + auto perPage = _items.empty() ? kEventsFirstPage : kEventsPerPage; + requestId = request(MTPchannels_GetAdminLog(MTP_flags(flags), _channel->inputChannel, MTP_string(query), filter, MTP_vector(admins), MTP_long(maxId), MTP_long(minId), MTP_int(perPage))).done([this, &requestId, &loadedFlag, direction](const MTPchannels_AdminLogResults &result) { Expects(result.type() == mtpc_channels_adminLogResults); requestId = 0; @@ -568,14 +583,15 @@ void InnerWidget::paintEvent(QPaintEvent *e) { } void InnerWidget::paintEmpty(Painter &p) { - //style::font font(st::msgServiceFont); - //int32 w = font->width(lang(lng_willbe_history)) + st::msgPadding.left() + st::msgPadding.right(), h = font->height + st::msgServicePadding.top() + st::msgServicePadding.bottom() + 2; - //QRect tr((width() - w) / 2, (height() - _field->height() - 2 * st::historySendPadding - h) / 2, w, h); - //HistoryLayout::ServiceMessagePainter::paintBubble(p, tr.x(), tr.y(), tr.width(), tr.height()); + style::font font(st::msgServiceFont); + auto rectWidth = st::historyAdminLogEmptyWidth; + auto innerWidth = rectWidth - st::historyAdminLogEmptyPadding.left() - st::historyAdminLogEmptyPadding.right(); + auto rectHeight = st::historyAdminLogEmptyPadding.top() + _emptyText.countHeight(innerWidth) + st::historyAdminLogEmptyPadding.bottom(); + auto rect = QRect((width() - rectWidth) / 2, (height() - rectHeight) / 3, rectWidth, rectHeight); + HistoryLayout::ServiceMessagePainter::paintBubble(p, rect.x(), rect.y(), rect.width(), rect.height()); - //p.setPen(st::msgServiceFg); - //p.setFont(font->f); - //p.drawText(tr.left() + st::msgPadding.left(), tr.top() + st::msgServicePadding.top() + 1 + font->ascent, lang(lng_willbe_history)); + p.setPen(st::msgServiceFg); + _emptyText.draw(p, rect.x() + st::historyAdminLogEmptyPadding.left(), rect.y() + st::historyAdminLogEmptyPadding.top(), innerWidth, style::al_top); } TextWithEntities InnerWidget::getSelectedText() const { diff --git a/Telegram/SourceFiles/history/history_admin_log_inner.h b/Telegram/SourceFiles/history/history_admin_log_inner.h index a64bdf504..7c25cc430 100644 --- a/Telegram/SourceFiles/history/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/history_admin_log_inner.h @@ -152,6 +152,7 @@ private: void itemsAdded(Direction direction); void updateSize(); void updateMinMaxIds(); + void updateEmptyText(); void paintEmpty(Painter &p); void toggleScrollDateShown(); @@ -218,6 +219,7 @@ private: // Don't load anything until the memento was read. bool _upLoaded = true; bool _downLoaded = true; + Text _emptyText; MouseAction _mouseAction = MouseAction::None; TextSelectType _mouseSelectType = TextSelectType::Letters; diff --git a/Telegram/SourceFiles/history/history_admin_log_section.cpp b/Telegram/SourceFiles/history/history_admin_log_section.cpp index 35bc07232..25d6ed4e8 100644 --- a/Telegram/SourceFiles/history/history_admin_log_section.cpp +++ b/Telegram/SourceFiles/history/history_admin_log_section.cpp @@ -73,6 +73,7 @@ FixedBar::FixedBar(QWidget *parent) : TWidget(parent) _backButton->moveToLeft(0, 0); _backButton->setClickedCallback([this] { goBack(); }); _filter->setClickedCallback([this] {}); + _filter->hide(); } void FixedBar::applyFilter(MTPDchannelAdminLogEventsFilter::Flags flags, const std::vector> &admins) { @@ -88,7 +89,7 @@ int FixedBar::resizeGetHeight(int newWidth) { auto newHeight = 0; auto buttonLeft = newWidth; - buttonLeft -= _filter->width(); _filter->moveToLeft(buttonLeft, 0); + //buttonLeft -= _filter->width(); _filter->moveToLeft(buttonLeft, 0); _backButton->resizeToWidth(buttonLeft); _backButton->moveToLeft(0, 0); newHeight += _backButton->height(); @@ -106,6 +107,7 @@ void FixedBar::setAnimatingMode(bool enabled) { } else { setAttribute(Qt::WA_OpaquePaintEvent); showChildren(); + _filter->hide(); } show(); } diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index 651212805..b52401fcd 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -4458,7 +4458,7 @@ HistoryLocation::HistoryLocation(gsl::not_null parent, const Locat , _data(App::location(coords)) , _title(st::msgMinWidth) , _description(st::msgMinWidth) -, _link(new LocationClickHandler(coords)) { +, _link(MakeShared(coords)) { if (!title.isEmpty()) { _title.setText(st::webPageTitleStyle, textClean(title), _webpageTitleOptions); } @@ -4474,7 +4474,7 @@ HistoryLocation::HistoryLocation(gsl::not_null parent, const Histo , _data(other._data) , _title(other._title) , _description(other._description) -, _link(new LocationClickHandler(_data->coords)) { +, _link(MakeShared(_data->coords)) { } void HistoryLocation::initDimensions() { diff --git a/Telegram/SourceFiles/lang/lang_tag.cpp b/Telegram/SourceFiles/lang/lang_tag.cpp index 83bb0273c..32bb224d9 100644 --- a/Telegram/SourceFiles/lang/lang_tag.cpp +++ b/Telegram/SourceFiles/lang/lang_tag.cpp @@ -169,9 +169,9 @@ PluralResult Plural(ushort keyBase, float64 value) { auto shift = (useNonDefaultPlural ? ChoosePlural : ChoosePluralEn)((integer ? i : -1), i, v, w, f, t); auto string = langpack.getValue(LangKey(keyBase + shift)); if (i == qCeil(n)) { - return { string, QString::number(value) }; + return { string, QString::number(qRound(value)) }; } - return { string, QString::number(qRound(value)) }; + return { string, QString::number(value) }; } void UpdatePluralRules(const QString &languageId) {