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-11-03 15:52:53 +00:00
|
|
|
#include "info/common_groups/info_common_groups_widget.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2017-11-03 15:52:53 +00:00
|
|
|
#include "info/common_groups/info_common_groups_inner_widget.h"
|
2017-10-31 18:25:22 +00:00
|
|
|
#include "info/info_controller.h"
|
2017-11-03 18:26:14 +00:00
|
|
|
#include "ui/search_field_controller.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.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"
|
2017-11-03 18:26:14 +00:00
|
|
|
#include "styles/style_info.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
namespace CommonGroups {
|
2017-09-15 17:34:41 +00:00
|
|
|
|
2020-06-08 09:06:50 +00:00
|
|
|
Memento::Memento(not_null<UserData*> user)
|
|
|
|
: ContentMemento(user, 0) {
|
|
|
|
}
|
|
|
|
|
2017-10-31 18:25:22 +00:00
|
|
|
Section Memento::section() const {
|
|
|
|
return Section(Section::Type::CommonGroups);
|
|
|
|
}
|
|
|
|
|
2020-06-08 09:06:50 +00:00
|
|
|
not_null<UserData*> Memento::user() const {
|
|
|
|
return peer()->asUser();
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
object_ptr<ContentWidget> Memento::createWidget(
|
|
|
|
QWidget *parent,
|
2017-10-31 18:25:22 +00:00
|
|
|
not_null<Controller*> controller,
|
2017-09-13 17:01:23 +00:00
|
|
|
const QRect &geometry) {
|
2020-06-08 09:06:50 +00:00
|
|
|
auto result = object_ptr<Widget>(parent, controller, user());
|
2017-09-13 17:01:23 +00:00
|
|
|
result->setInternalState(geometry, this);
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 18:26:14 +00:00
|
|
|
void Memento::setListState(std::unique_ptr<PeerListState> state) {
|
|
|
|
_listState = std::move(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<PeerListState> Memento::listState() {
|
|
|
|
return std::move(_listState);
|
|
|
|
}
|
|
|
|
|
|
|
|
Memento::~Memento() = default;
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
Widget::Widget(
|
|
|
|
QWidget *parent,
|
2017-10-31 18:25:22 +00:00
|
|
|
not_null<Controller*> controller,
|
2017-09-13 17:01:23 +00:00
|
|
|
not_null<UserData*> user)
|
2017-10-31 18:25:22 +00:00
|
|
|
: ContentWidget(parent, controller) {
|
2017-10-10 20:39:44 +00:00
|
|
|
_inner = setInnerWidget(object_ptr<InnerWidget>(
|
|
|
|
this,
|
|
|
|
controller,
|
|
|
|
user));
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
not_null<UserData*> Widget::user() const {
|
|
|
|
return _inner->user();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::showInternal(not_null<ContentMemento*> memento) {
|
2017-10-31 18:25:22 +00:00
|
|
|
if (!controller()->validateMementoPeer(memento)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-13 17:01:23 +00:00
|
|
|
if (auto groupsMemento = dynamic_cast<Memento*>(memento.get())) {
|
2020-06-08 09:06:50 +00:00
|
|
|
if (groupsMemento->user() == user()) {
|
2017-09-13 17:01:23 +00:00
|
|
|
restoreState(groupsMemento);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-17 13:23:36 +00:00
|
|
|
void Widget::setInternalState(
|
|
|
|
const QRect &geometry,
|
|
|
|
not_null<Memento*> memento) {
|
2017-09-13 17:01:23 +00:00
|
|
|
setGeometry(geometry);
|
2017-12-26 12:41:48 +00:00
|
|
|
Ui::SendPendingMoveResizeEvents(this);
|
2017-09-13 17:01:23 +00:00
|
|
|
restoreState(memento);
|
|
|
|
}
|
|
|
|
|
2020-12-14 14:48:10 +00:00
|
|
|
std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
|
|
|
|
auto result = std::make_shared<Memento>(user());
|
2017-09-13 17:01:23 +00:00
|
|
|
saveState(result.get());
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::saveState(not_null<Memento*> memento) {
|
|
|
|
memento->setScrollTop(scrollTopSave());
|
|
|
|
_inner->saveState(memento);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::restoreState(not_null<Memento*> memento) {
|
|
|
|
_inner->restoreState(memento);
|
|
|
|
auto scrollTop = memento->scrollTop();
|
|
|
|
scrollTopRestore(memento->scrollTop());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace CommonGroups
|
|
|
|
} // namespace Info
|
|
|
|
|