tdesktop/Telegram/SourceFiles/info/info_controller.h

220 lines
5.1 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
*/
#pragma once
#include <rpl/variable.h>
#include "data/data_search_controller.h"
#include "window/window_session_controller.h"
2018-09-05 19:05:49 +00:00
#include "settings/settings_common.h"
namespace Ui {
class SearchFieldController;
} // namespace Ui
namespace Info {
2018-09-05 19:05:49 +00:00
namespace Settings {
struct Tag {
explicit Tag(not_null<UserData*> self) : self(self) {
}
not_null<UserData*> self;
};
} // namespace Settings
2018-01-22 19:51:38 +00:00
class Key {
public:
Key(not_null<PeerData*> peer);
2019-04-15 11:54:03 +00:00
//Key(not_null<Data::Feed*> feed); // #feed
2018-09-05 19:05:49 +00:00
Key(Settings::Tag settings);
2018-01-22 19:51:38 +00:00
PeerData *peer() const;
2019-04-15 11:54:03 +00:00
//Data::Feed *feed() const; // #feed
2018-09-05 19:05:49 +00:00
UserData *settingsSelf() const;
2018-01-22 19:51:38 +00:00
private:
2018-09-05 19:05:49 +00:00
base::variant<
not_null<PeerData*>,
2019-04-15 11:54:03 +00:00
//not_null<Data::Feed*>, // #feed
2018-09-05 19:05:49 +00:00
Settings::Tag> _value;
2018-01-22 19:51:38 +00:00
};
enum class Wrap;
class WrapWidget;
class Memento;
class ContentMemento;
class Section final {
public:
enum class Type {
Profile,
Media,
CommonGroups,
Members,
2019-04-15 11:54:03 +00:00
//Channels, // #feed
2018-09-05 19:05:49 +00:00
Settings,
};
2018-09-05 19:05:49 +00:00
using SettingsType = ::Settings::Type;
using MediaType = Storage::SharedMediaType;
Section(Type type) : _type(type) {
2018-09-05 19:05:49 +00:00
Expects(type != Type::Media && type != Type::Settings);
}
Section(MediaType mediaType)
: _type(Type::Media)
, _mediaType(mediaType) {
}
2018-09-05 19:05:49 +00:00
Section(SettingsType settingsType)
: _type(Type::Settings)
, _settingsType(settingsType) {
}
Type type() const {
return _type;
}
MediaType mediaType() const {
Expects(_type == Type::Media);
2018-09-05 19:05:49 +00:00
return _mediaType;
}
2018-09-05 19:05:49 +00:00
SettingsType settingsType() const {
Expects(_type == Type::Settings);
return _settingsType;
}
private:
Type _type;
2018-09-05 19:05:49 +00:00
MediaType _mediaType = MediaType();
SettingsType _settingsType = SettingsType();
};
class AbstractController : public Window::SessionNavigation {
public:
AbstractController(not_null<Window::SessionController*> parent);
2018-01-22 19:51:38 +00:00
virtual Key key() const = 0;
virtual PeerData *migrated() const = 0;
virtual Section section() const = 0;
PeerId peerId() const;
PeerId migratedPeerId() const;
2019-04-15 11:54:03 +00:00
//Data::Feed *feed() const { // #feed
// return key().feed();
//}
2018-09-05 19:05:49 +00:00
UserData *settingsSelf() const {
return key().settingsSelf();
}
virtual void setSearchEnabledByContent(bool enabled) {
}
virtual rpl::producer<SparseIdsMergedSlice> mediaSource(
SparseIdsMergedSlice::UniversalMsgId aroundId,
int limitBefore,
int limitAfter) const;
virtual rpl::producer<QString> mediaSourceQueryValue() const;
void showSection(
Window::SectionMemento &&memento,
const Window::SectionShow &params = Window::SectionShow()) override;
void showBackFromStack(
const Window::SectionShow &params = Window::SectionShow()) override;
not_null<Window::SessionController*> parentController() override {
return _parent;
}
private:
not_null<Window::SessionController*> _parent;
};
class Controller : public AbstractController {
public:
Controller(
not_null<WrapWidget*> widget,
not_null<Window::SessionController*> window,
not_null<ContentMemento*> memento);
2018-01-22 19:51:38 +00:00
Key key() const override {
return _key;
}
PeerData *migrated() const override {
return _migrated;
}
Section section() const override {
return _section;
}
bool validateMementoPeer(
not_null<ContentMemento*> memento) const;
Wrap wrap() const;
rpl::producer<Wrap> wrapValue() const;
2017-11-03 15:47:08 +00:00
void setSection(not_null<ContentMemento*> memento);
Ui::SearchFieldController *searchFieldController() const {
return _searchFieldController.get();
}
void setSearchEnabledByContent(bool enabled) override {
_seachEnabledByContent = enabled;
}
2017-11-21 09:20:56 +00:00
rpl::producer<bool> searchEnabledByContent() const;
rpl::producer<SparseIdsMergedSlice> mediaSource(
SparseIdsMergedSlice::UniversalMsgId aroundId,
int limitBefore,
int limitAfter) const override;
rpl::producer<QString> mediaSourceQueryValue() const override;
bool takeSearchStartsFocused() {
return base::take(_searchStartsFocused);
}
void setCanSaveChanges(rpl::producer<bool> can);
rpl::producer<bool> canSaveChanges() const;
bool canSaveChangesNow() const;
2017-11-03 15:47:08 +00:00
void saveSearchState(not_null<ContentMemento*> memento);
void showSection(
Window::SectionMemento &&memento,
const Window::SectionShow &params = Window::SectionShow()) override;
void showBackFromStack(
const Window::SectionShow &params = Window::SectionShow()) override;
rpl::lifetime &lifetime() {
return _lifetime;
}
~Controller();
private:
using SearchQuery = Api::DelayedSearchController::Query;
2017-11-03 15:47:08 +00:00
void updateSearchControllers(not_null<ContentMemento*> memento);
SearchQuery produceSearchQuery(const QString &query) const;
void setupMigrationViewer();
not_null<WrapWidget*> _widget;
2018-01-22 19:51:38 +00:00
Key _key;
PeerData *_migrated = nullptr;
rpl::variable<Wrap> _wrap;
Section _section;
std::unique_ptr<Ui::SearchFieldController> _searchFieldController;
std::unique_ptr<Api::DelayedSearchController> _searchController;
rpl::variable<bool> _seachEnabledByContent = false;
rpl::variable<bool> _canSaveChanges = false;
bool _searchStartsFocused = false;
rpl::lifetime _lifetime;
};
} // namespace Info