2017-09-13 17:01:23 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-09-13 17:01:23 +00:00
|
|
|
*/
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "info/media/info_media_inner_widget.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2017-10-20 16:19:42 +00:00
|
|
|
#include <rpl/flatten_latest.h>
|
2017-10-04 12:39:59 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
|
|
|
#include "info/media/info_media_list_widget.h"
|
|
|
|
#include "info/media/info_media_buttons.h"
|
2017-11-14 17:22:44 +00:00
|
|
|
#include "info/media/info_media_empty_widget.h"
|
2017-10-04 12:39:59 +00:00
|
|
|
#include "info/profile/info_profile_icon.h"
|
2017-10-31 18:25:22 +00:00
|
|
|
#include "info/info_controller.h"
|
2022-10-11 15:08:19 +00:00
|
|
|
#include "data/data_forum_topic.h"
|
2017-10-04 12:39:59 +00:00
|
|
|
#include "ui/widgets/discrete_sliders.h"
|
2017-10-04 17:15:08 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2019-11-02 17:06:47 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "ui/widgets/box_content_divider.h"
|
2017-10-04 12:39:59 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2017-10-30 19:24:20 +00:00
|
|
|
#include "ui/search_field_controller.h"
|
2017-10-04 12:39:59 +00:00
|
|
|
#include "styles/style_info.h"
|
|
|
|
#include "lang/lang_keys.h"
|
2017-10-03 17:41:44 +00:00
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
namespace Info {
|
|
|
|
namespace Media {
|
|
|
|
|
|
|
|
InnerWidget::InnerWidget(
|
|
|
|
QWidget *parent,
|
2017-10-31 18:25:22 +00:00
|
|
|
not_null<Controller*> controller)
|
|
|
|
: RpWidget(parent)
|
2017-11-14 17:22:44 +00:00
|
|
|
, _controller(controller)
|
|
|
|
, _empty(this) {
|
2017-12-22 07:05:20 +00:00
|
|
|
_empty->heightValue(
|
|
|
|
) | rpl::start_with_next(
|
|
|
|
[this] { refreshHeight(); },
|
|
|
|
_empty->lifetime());
|
2017-10-31 18:25:22 +00:00
|
|
|
_list = setupList();
|
2017-10-04 12:39:59 +00:00
|
|
|
}
|
|
|
|
|
2017-11-16 09:13:17 +00:00
|
|
|
// Allows showing additional shared media links and tabs.
|
2022-10-12 12:57:17 +00:00
|
|
|
// Used for shared media in Saved Messages.
|
2017-12-05 12:23:08 +00:00
|
|
|
void InnerWidget::setupOtherTypes() {
|
2023-12-27 01:09:20 +00:00
|
|
|
if (_controller->key().peer()->sharedMediaInfo() && _isStackBottom) {
|
2017-12-05 12:23:08 +00:00
|
|
|
createOtherTypes();
|
|
|
|
} else {
|
|
|
|
_otherTypes.destroy();
|
|
|
|
refreshHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InnerWidget::createOtherTypes() {
|
|
|
|
_otherTypes.create(this);
|
|
|
|
_otherTypes->show();
|
|
|
|
|
|
|
|
createTypeButtons();
|
2019-09-18 11:19:05 +00:00
|
|
|
_otherTypes->add(object_ptr<Ui::BoxContentDivider>(_otherTypes));
|
2017-12-05 12:23:08 +00:00
|
|
|
|
|
|
|
_otherTypes->resizeToWidth(width());
|
2017-12-22 07:05:20 +00:00
|
|
|
_otherTypes->heightValue(
|
|
|
|
) | rpl::start_with_next(
|
|
|
|
[this] { refreshHeight(); },
|
|
|
|
_otherTypes->lifetime());
|
2017-12-05 12:23:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InnerWidget::createTypeButtons() {
|
|
|
|
auto wrap = _otherTypes->add(object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
_otherTypes,
|
|
|
|
object_ptr<Ui::VerticalLayout>(_otherTypes)));
|
|
|
|
auto content = wrap->entity();
|
|
|
|
content->add(object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
content,
|
|
|
|
st::infoProfileSkip));
|
|
|
|
|
|
|
|
auto tracker = Ui::MultiSlideTracker();
|
2022-10-11 15:08:19 +00:00
|
|
|
const auto peer = _controller->key().peer();
|
|
|
|
const auto topic = _controller->key().topic();
|
|
|
|
const auto topicRootId = topic ? topic->rootId() : MsgId();
|
|
|
|
const auto migrated = _controller->migrated();
|
|
|
|
const auto addMediaButton = [&](
|
2017-12-05 12:23:08 +00:00
|
|
|
Type buttonType,
|
|
|
|
const style::icon &icon) {
|
|
|
|
if (buttonType == type()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto result = AddButton(
|
|
|
|
content,
|
|
|
|
_controller,
|
2022-10-11 15:08:19 +00:00
|
|
|
peer,
|
|
|
|
topicRootId,
|
|
|
|
migrated,
|
2017-12-05 12:23:08 +00:00
|
|
|
buttonType,
|
|
|
|
tracker);
|
|
|
|
object_ptr<Profile::FloatingIcon>(
|
|
|
|
result,
|
|
|
|
icon,
|
|
|
|
st::infoSharedMediaButtonIconPosition)->show();
|
|
|
|
};
|
|
|
|
|
|
|
|
addMediaButton(Type::Photo, st::infoIconMediaPhoto);
|
|
|
|
addMediaButton(Type::Video, st::infoIconMediaVideo);
|
|
|
|
addMediaButton(Type::File, st::infoIconMediaFile);
|
|
|
|
addMediaButton(Type::MusicFile, st::infoIconMediaAudio);
|
|
|
|
addMediaButton(Type::Link, st::infoIconMediaLink);
|
2020-05-04 12:50:46 +00:00
|
|
|
addMediaButton(Type::RoundVoiceFile, st::infoIconMediaVoice);
|
2020-08-23 19:42:28 +00:00
|
|
|
addMediaButton(Type::GIF, st::infoIconMediaGif);
|
2017-12-05 12:23:08 +00:00
|
|
|
|
|
|
|
content->add(object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
content,
|
|
|
|
st::infoProfileSkip));
|
|
|
|
wrap->toggleOn(tracker.atLeastOneShownValue());
|
|
|
|
wrap->finishAnimating();
|
|
|
|
}
|
|
|
|
|
2017-10-04 12:39:59 +00:00
|
|
|
Type InnerWidget::type() const {
|
2017-10-31 18:25:22 +00:00
|
|
|
return _controller->section().mediaType();
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InnerWidget::visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) {
|
2017-10-05 15:35:52 +00:00
|
|
|
setChildVisibleTopBottom(_list, visibleTop, visibleBottom);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 12:39:59 +00:00
|
|
|
bool InnerWidget::showInternal(not_null<Memento*> memento) {
|
2017-10-31 18:25:22 +00:00
|
|
|
if (!_controller->validateMementoPeer(memento)) {
|
2017-10-04 12:39:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto mementoType = memento->section().mediaType();
|
|
|
|
if (mementoType == type()) {
|
|
|
|
restoreState(memento);
|
|
|
|
return true;
|
2017-10-30 19:24:20 +00:00
|
|
|
}
|
2017-11-16 09:13:17 +00:00
|
|
|
return false;
|
2017-10-31 18:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
object_ptr<ListWidget> InnerWidget::setupList() {
|
2017-10-04 12:39:59 +00:00
|
|
|
auto result = object_ptr<ListWidget>(
|
|
|
|
this,
|
2017-10-31 18:25:22 +00:00
|
|
|
_controller);
|
2017-12-22 07:05:20 +00:00
|
|
|
result->heightValue(
|
|
|
|
) | rpl::start_with_next(
|
|
|
|
[this] { refreshHeight(); },
|
|
|
|
result->lifetime());
|
2017-10-05 17:32:34 +00:00
|
|
|
using namespace rpl::mappers;
|
2017-12-22 07:05:20 +00:00
|
|
|
result->scrollToRequests(
|
|
|
|
) | rpl::map([widget = result.data()](int to) {
|
|
|
|
return Ui::ScrollToRequest {
|
|
|
|
widget->y() + to,
|
|
|
|
-1
|
|
|
|
};
|
|
|
|
}) | rpl::start_to_stream(
|
|
|
|
_scrollToRequests,
|
|
|
|
result->lifetime());
|
2017-10-20 16:19:42 +00:00
|
|
|
_selectedLists.fire(result->selectedListValue());
|
2017-11-14 17:22:44 +00:00
|
|
|
_listTops.fire(result->topValue());
|
|
|
|
_empty->setType(_controller->section().mediaType());
|
2017-12-22 07:05:20 +00:00
|
|
|
_controller->mediaSourceQueryValue(
|
|
|
|
) | rpl::start_with_next([this](const QString &query) {
|
|
|
|
_empty->setSearchQuery(query);
|
|
|
|
}, result->lifetime());
|
2017-10-04 12:39:59 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
void InnerWidget::saveState(not_null<Memento*> memento) {
|
2017-10-27 17:41:38 +00:00
|
|
|
_list->saveState(memento);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InnerWidget::restoreState(not_null<Memento*> memento) {
|
2017-10-27 17:41:38 +00:00
|
|
|
_list->restoreState(memento);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 16:19:42 +00:00
|
|
|
rpl::producer<SelectedItems> InnerWidget::selectedListValue() const {
|
2017-12-22 07:05:20 +00:00
|
|
|
return _selectedLists.events_starting_with(
|
|
|
|
_list->selectedListValue()
|
|
|
|
) | rpl::flatten_latest();
|
2017-10-20 16:19:42 +00:00
|
|
|
}
|
|
|
|
|
2022-02-27 11:14:39 +00:00
|
|
|
void InnerWidget::selectionAction(SelectionAction action) {
|
|
|
|
_list->selectionAction(action);
|
2017-10-20 16:19:42 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 19:24:20 +00:00
|
|
|
InnerWidget::~InnerWidget() = default;
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
int InnerWidget::resizeGetHeight(int newWidth) {
|
2017-10-04 12:39:59 +00:00
|
|
|
_inResize = true;
|
|
|
|
auto guard = gsl::finally([this] { _inResize = false; });
|
|
|
|
|
2017-12-05 12:23:08 +00:00
|
|
|
if (_otherTypes) {
|
|
|
|
_otherTypes->resizeToWidth(newWidth);
|
|
|
|
}
|
2017-10-04 12:39:59 +00:00
|
|
|
_list->resizeToWidth(newWidth);
|
2017-11-14 17:22:44 +00:00
|
|
|
_empty->resizeToWidth(newWidth);
|
2017-10-04 12:39:59 +00:00
|
|
|
return recountHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InnerWidget::refreshHeight() {
|
|
|
|
if (_inResize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resize(width(), recountHeight());
|
|
|
|
}
|
|
|
|
|
|
|
|
int InnerWidget::recountHeight() {
|
|
|
|
auto top = 0;
|
2017-12-05 12:23:08 +00:00
|
|
|
if (_otherTypes) {
|
|
|
|
_otherTypes->moveToLeft(0, top);
|
|
|
|
top += _otherTypes->heightNoMargins() - st::lineWidth;
|
|
|
|
}
|
2017-11-14 17:22:44 +00:00
|
|
|
auto listHeight = 0;
|
2017-10-04 12:39:59 +00:00
|
|
|
if (_list) {
|
|
|
|
_list->moveToLeft(0, top);
|
2017-11-14 17:22:44 +00:00
|
|
|
listHeight = _list->heightNoMargins();
|
|
|
|
top += listHeight;
|
|
|
|
}
|
|
|
|
if (listHeight > 0) {
|
|
|
|
_empty->hide();
|
|
|
|
} else {
|
|
|
|
_empty->show();
|
|
|
|
_empty->moveToLeft(0, top);
|
|
|
|
top += _empty->heightNoMargins();
|
2017-10-04 12:39:59 +00:00
|
|
|
}
|
|
|
|
return top;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-14 17:22:44 +00:00
|
|
|
void InnerWidget::setScrollHeightValue(rpl::producer<int> value) {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
_empty->setFullHeight(rpl::combine(
|
|
|
|
std::move(value),
|
2017-12-22 07:05:20 +00:00
|
|
|
_listTops.events_starting_with(
|
|
|
|
_list->topValue()
|
|
|
|
) | rpl::flatten_latest(),
|
2017-11-20 12:32:55 +00:00
|
|
|
_1 - _2));
|
2017-11-14 17:22:44 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 09:20:56 +00:00
|
|
|
rpl::producer<Ui::ScrollToRequest> InnerWidget::scrollToRequests() const {
|
|
|
|
return _scrollToRequests.events();
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
} // namespace Media
|
|
|
|
} // namespace Info
|