tdesktop/Telegram/SourceFiles/info/info_memento.cpp

229 lines
6.3 KiB
C++
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "info/info_memento.h"
2017-09-24 15:46:37 +00:00
#include "info/profile/info_profile_widget.h"
#include "info/media/info_media_widget.h"
#include "info/members/info_members_widget.h"
2019-04-15 11:54:03 +00:00
//#include "info/channels/info_channels_widget.h" // #feed
2017-11-03 15:52:53 +00:00
#include "info/common_groups/info_common_groups_widget.h"
2019-04-15 11:54:03 +00:00
//#include "info/feed/info_feed_profile_widget.h" // #feed
2018-09-05 19:05:49 +00:00
#include "info/settings/info_settings_widget.h"
#include "info/polls/info_polls_results_widget.h"
#include "info/info_section_widget.h"
#include "info/info_layer_widget.h"
#include "info/info_controller.h"
2019-09-13 12:22:54 +00:00
#include "ui/ui_utility.h"
#include "boxes/peer_list_box.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
2019-01-18 12:27:37 +00:00
#include "data/data_session.h"
2019-07-24 11:45:24 +00:00
#include "main/main_session.h"
namespace Info {
2020-06-08 09:06:50 +00:00
Memento::Memento(not_null<PeerData*> peer)
: Memento(peer, Section::Type::Profile) {
}
2020-06-08 09:06:50 +00:00
Memento::Memento(not_null<PeerData*> peer, Section section)
: Memento(DefaultStack(peer, section)) {
}
2019-04-15 11:54:03 +00:00
//Memento::Memento(not_null<Data::Feed*> feed, Section section) // #feed
//: Memento(DefaultStack(feed, section)) {
//}
//
2018-09-05 19:05:49 +00:00
Memento::Memento(Settings::Tag settings, Section section)
: Memento(DefaultStack(settings, section)) {
}
Memento::Memento(not_null<PollData*> poll, FullMsgId contextId)
: Memento(DefaultStack(poll, contextId)) {
}
Memento::Memento(std::vector<std::unique_ptr<ContentMemento>> stack)
: _stack(std::move(stack)) {
}
std::vector<std::unique_ptr<ContentMemento>> Memento::DefaultStack(
2020-06-08 09:06:50 +00:00
not_null<PeerData*> peer,
Section section) {
auto result = std::vector<std::unique_ptr<ContentMemento>>();
2020-06-08 09:06:50 +00:00
result.push_back(DefaultContent(peer, section));
return result;
}
2019-04-15 11:54:03 +00:00
//std::vector<std::unique_ptr<ContentMemento>> Memento::DefaultStack( // #feed
// not_null<Data::Feed*> feed,
// Section section) {
// auto result = std::vector<std::unique_ptr<ContentMemento>>();
// result.push_back(DefaultContent(feed, section));
// return result;
//}
//
2018-09-05 19:05:49 +00:00
std::vector<std::unique_ptr<ContentMemento>> Memento::DefaultStack(
Settings::Tag settings,
Section section) {
auto result = std::vector<std::unique_ptr<ContentMemento>>();
result.push_back(std::make_unique<Settings::Memento>(
settings.self,
section.settingsType()));
return result;
}
std::vector<std::unique_ptr<ContentMemento>> Memento::DefaultStack(
not_null<PollData*> poll,
FullMsgId contextId) {
auto result = std::vector<std::unique_ptr<ContentMemento>>();
result.push_back(std::make_unique<Polls::Memento>(poll, contextId));
return result;
}
2019-04-15 11:54:03 +00:00
Section Memento::DefaultSection(not_null<PeerData*> peer) {
2020-09-11 15:33:26 +00:00
if (peer->sharedMediaInfo()) {
2019-04-15 11:54:03 +00:00
return Section(Section::MediaType::Photo);
2018-01-22 19:51:38 +00:00
}
return Section(Section::Type::Profile);
}
2019-04-15 11:54:03 +00:00
// // #feed
//Section Memento::DefaultSection(Dialogs::Key key) {
// if (const auto peer = key.peer()) {
2020-09-11 15:33:26 +00:00
// if (peer->sharedMediaInfo()) {
2019-04-15 11:54:03 +00:00
// return Section(Section::MediaType::Photo);
// }
// }
// return Section(Section::Type::Profile);
//}
Memento Memento::Default(not_null<PeerData*> peer) {
2020-06-08 09:06:50 +00:00
return Memento(peer, DefaultSection(peer));
}
2019-04-15 11:54:03 +00:00
// // #feed
//Memento Memento::Default(Dialogs::Key key) {
// if (const auto peer = key.peer()) {
// return Memento(peer->id, DefaultSection(key));
// }
// return Memento(key.feed(), DefaultSection(key));
//}
std::unique_ptr<ContentMemento> Memento::DefaultContent(
2020-06-08 09:06:50 +00:00
not_null<PeerData*> peer,
Section section) {
if (auto to = peer->migrateTo()) {
peer = to;
}
auto migrated = peer->migrateFrom();
auto migratedPeerId = migrated ? migrated->id : PeerId(0);
switch (section.type()) {
case Section::Type::Profile:
return std::make_unique<Profile::Memento>(
2020-06-08 09:06:50 +00:00
peer,
migratedPeerId);
case Section::Type::Media:
return std::make_unique<Media::Memento>(
2020-06-08 09:06:50 +00:00
peer,
migratedPeerId,
section.mediaType());
case Section::Type::CommonGroups:
2020-06-08 09:06:50 +00:00
return std::make_unique<CommonGroups::Memento>(peer->asUser());
case Section::Type::Members:
return std::make_unique<Members::Memento>(
2020-06-08 09:06:50 +00:00
peer,
migratedPeerId);
}
Unexpected("Wrong section type in Info::Memento::DefaultContent()");
}
2019-04-15 11:54:03 +00:00
//
//std::unique_ptr<ContentMemento> Memento::DefaultContent( // #feed
// not_null<Data::Feed*> feed,
// Section section) {
// switch (section.type()) {
// case Section::Type::Profile:
// return std::make_unique<FeedProfile::Memento>(feed);
// case Section::Type::Channels:
// return std::make_unique<Channels::Memento>(feed);
// }
// Unexpected("Wrong feed section in Info::Memento::DefaultContent()");
//}
2018-01-22 19:51:38 +00:00
object_ptr<Window::SectionWidget> Memento::createWidget(
QWidget *parent,
not_null<Window::SessionController*> controller,
Window::Column column,
const QRect &geometry) {
auto wrap = (column == Window::Column::Third)
? Wrap::Side
: Wrap::Narrow;
auto result = object_ptr<SectionWidget>(
parent,
controller,
wrap,
this);
result->setGeometry(geometry);
return result;
}
2019-09-18 11:19:05 +00:00
object_ptr<Ui::LayerWidget> Memento::createLayer(
not_null<Window::SessionController*> controller,
const QRect &geometry) {
if (geometry.width() >= LayerWidget::MinimalSupportedWidth()) {
return object_ptr<LayerWidget>(controller, this);
}
return nullptr;
}
std::vector<std::unique_ptr<ContentMemento>> Memento::takeStack() {
return std::move(_stack);
}
Memento::~Memento() = default;
MoveMemento::MoveMemento(object_ptr<WrapWidget> content)
: _content(std::move(content)) {
_content->hide();
_content->setParent(nullptr);
}
object_ptr<Window::SectionWidget> MoveMemento::createWidget(
QWidget *parent,
not_null<Window::SessionController*> controller,
Window::Column column,
const QRect &geometry) {
auto wrap = (column == Window::Column::Third)
? Wrap::Side
: Wrap::Narrow;
auto result = object_ptr<SectionWidget>(
parent,
controller,
wrap,
this);
result->setGeometry(geometry);
return result;
}
2019-09-18 11:19:05 +00:00
object_ptr<Ui::LayerWidget> MoveMemento::createLayer(
not_null<Window::SessionController*> controller,
const QRect &geometry) {
if (geometry.width() < LayerWidget::MinimalSupportedWidth()) {
return nullptr;
}
return object_ptr<LayerWidget>(controller, this);
}
object_ptr<WrapWidget> MoveMemento::takeContent(
QWidget *parent,
Wrap wrap) {
Ui::AttachParentChild(parent, _content);
_content->setWrap(wrap);
return std::move(_content);
}
} // namespace Info