2017-03-27 12:24:38 +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-03-27 12:24:38 +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-03-27 12:24:38 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-09-20 18:40:23 +00:00
|
|
|
#include <rpl/variable.h>
|
2017-08-31 16:28:58 +00:00
|
|
|
#include "base/flags.h"
|
2018-01-22 16:42:25 +00:00
|
|
|
#include "dialogs/dialogs_key.h"
|
2017-08-31 16:28:58 +00:00
|
|
|
|
2017-09-15 17:34:41 +00:00
|
|
|
class MainWidget;
|
2018-01-11 19:33:26 +00:00
|
|
|
class HistoryMessage;
|
|
|
|
class HistoryService;
|
|
|
|
|
2018-01-21 14:49:42 +00:00
|
|
|
namespace Media {
|
|
|
|
namespace Player {
|
|
|
|
class RoundController;
|
|
|
|
} // namespace Player
|
|
|
|
} // namespace Media
|
|
|
|
|
2017-03-27 12:24:38 +00:00
|
|
|
namespace Window {
|
|
|
|
|
2017-10-13 17:35:29 +00:00
|
|
|
class LayerWidget;
|
2017-12-04 07:33:33 +00:00
|
|
|
class MainWindow;
|
|
|
|
class SectionMemento;
|
2017-10-13 17:35:29 +00:00
|
|
|
|
2017-04-07 18:10:49 +00:00
|
|
|
enum class GifPauseReason {
|
2017-09-03 18:36:06 +00:00
|
|
|
Any = 0,
|
2017-04-07 18:10:49 +00:00
|
|
|
InlineResults = (1 << 0),
|
2017-09-03 18:36:06 +00:00
|
|
|
SavedGifs = (1 << 1),
|
|
|
|
Layer = (1 << 2),
|
|
|
|
RoundPlaying = (1 << 3),
|
|
|
|
MediaPreview = (1 << 4),
|
2017-04-07 18:10:49 +00:00
|
|
|
};
|
2017-08-31 16:28:58 +00:00
|
|
|
using GifPauseReasons = base::flags<GifPauseReason>;
|
|
|
|
inline constexpr bool is_flag_type(GifPauseReason) { return true; };
|
2017-04-07 18:10:49 +00:00
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
struct SectionShow {
|
|
|
|
enum class Way {
|
|
|
|
Forward,
|
|
|
|
Backward,
|
|
|
|
ClearStack,
|
|
|
|
};
|
|
|
|
SectionShow(
|
2017-10-03 17:41:44 +00:00
|
|
|
Way way = Way::Forward,
|
2017-10-03 13:05:58 +00:00
|
|
|
anim::type animated = anim::type::normal,
|
|
|
|
anim::activation activation = anim::activation::normal)
|
|
|
|
: way(way)
|
|
|
|
, animated(animated)
|
|
|
|
, activation(activation) {
|
|
|
|
}
|
|
|
|
SectionShow(
|
|
|
|
anim::type animated,
|
|
|
|
anim::activation activation = anim::activation::normal)
|
|
|
|
: animated(animated)
|
|
|
|
, activation(activation) {
|
|
|
|
}
|
|
|
|
|
|
|
|
SectionShow withWay(Way newWay) const {
|
|
|
|
return SectionShow(newWay, animated, activation);
|
|
|
|
}
|
2017-12-04 07:33:33 +00:00
|
|
|
SectionShow withThirdColumn() const {
|
|
|
|
auto copy = *this;
|
|
|
|
copy.thirdColumn = true;
|
|
|
|
return copy;
|
|
|
|
}
|
2017-10-03 13:05:58 +00:00
|
|
|
|
|
|
|
Way way = Way::Forward;
|
|
|
|
anim::type animated = anim::type::normal;
|
|
|
|
anim::activation activation = anim::activation::normal;
|
2017-12-04 07:33:33 +00:00
|
|
|
bool thirdColumn = false;
|
2017-10-03 13:05:58 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-12-04 07:33:33 +00:00
|
|
|
class Controller;
|
|
|
|
|
|
|
|
class Navigation {
|
|
|
|
public:
|
|
|
|
virtual void showSection(
|
|
|
|
SectionMemento &&memento,
|
|
|
|
const SectionShow ¶ms = SectionShow()) = 0;
|
|
|
|
virtual void showBackFromStack(
|
|
|
|
const SectionShow ¶ms = SectionShow()) = 0;
|
|
|
|
virtual not_null<Controller*> parentController() = 0;
|
|
|
|
|
|
|
|
void showPeerInfo(
|
|
|
|
PeerId peerId,
|
|
|
|
const SectionShow ¶ms = SectionShow());
|
|
|
|
void showPeerInfo(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const SectionShow ¶ms = SectionShow());
|
|
|
|
void showPeerInfo(
|
|
|
|
not_null<History*> history,
|
|
|
|
const SectionShow ¶ms = SectionShow());
|
|
|
|
|
2018-01-21 14:49:42 +00:00
|
|
|
virtual ~Navigation() = default;
|
|
|
|
|
2017-12-04 07:33:33 +00:00
|
|
|
};
|
2017-04-07 18:10:49 +00:00
|
|
|
|
2017-12-04 07:33:33 +00:00
|
|
|
class Controller : public Navigation {
|
2017-03-27 12:24:38 +00:00
|
|
|
public:
|
2018-01-21 14:49:42 +00:00
|
|
|
Controller(not_null<MainWindow*> window);
|
2017-04-07 18:10:49 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<MainWindow*> window() const {
|
2017-04-07 18:10:49 +00:00
|
|
|
return _window;
|
2017-03-27 12:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is needed for History TopBar updating when searchInPeer
|
|
|
|
// is changed in the DialogsWidget of the current window.
|
2017-09-20 18:40:23 +00:00
|
|
|
rpl::variable<PeerData*> searchInPeer;
|
2017-03-27 12:24:38 +00:00
|
|
|
|
|
|
|
// This is needed while we have one HistoryWidget and one TopBarWidget
|
|
|
|
// for all histories we show in a window. Once each history is shown
|
|
|
|
// in its own HistoryWidget with its own TopBarWidget this can be removed.
|
2017-11-08 16:45:30 +00:00
|
|
|
//
|
|
|
|
// Also used in the Info::Profile to toggle Send Message button.
|
2017-09-20 18:40:23 +00:00
|
|
|
rpl::variable<PeerData*> historyPeer;
|
2017-03-27 12:24:38 +00:00
|
|
|
|
2018-01-22 16:42:25 +00:00
|
|
|
void setActiveChatEntry(Dialogs::RowDescriptor row);
|
|
|
|
void setActiveChatEntry(Dialogs::Key key);
|
|
|
|
Dialogs::RowDescriptor activeChatEntryCurrent() const;
|
|
|
|
Dialogs::Key activeChatCurrent() const;
|
|
|
|
rpl::producer<Dialogs::RowDescriptor> activeChatEntryChanges() const;
|
|
|
|
rpl::producer<Dialogs::Key> activeChatChanges() const;
|
|
|
|
rpl::producer<Dialogs::RowDescriptor> activeChatEntryValue() const;
|
|
|
|
rpl::producer<Dialogs::Key> activeChatValue() const;
|
2017-11-08 16:45:30 +00:00
|
|
|
|
2017-04-07 18:10:49 +00:00
|
|
|
void enableGifPauseReason(GifPauseReason reason);
|
|
|
|
void disableGifPauseReason(GifPauseReason reason);
|
|
|
|
base::Observable<void> &gifPauseLevelChanged() {
|
|
|
|
return _gifPauseLevelChanged;
|
|
|
|
}
|
|
|
|
bool isGifPausedAtLeastFor(GifPauseReason reason) const;
|
2017-05-23 14:04:59 +00:00
|
|
|
base::Observable<void> &floatPlayerAreaUpdated() {
|
|
|
|
return _floatPlayerAreaUpdated;
|
|
|
|
}
|
2017-04-07 18:10:49 +00:00
|
|
|
|
2017-04-09 18:06:06 +00:00
|
|
|
struct ColumnLayout {
|
|
|
|
int bodyWidth;
|
|
|
|
int dialogsWidth;
|
2017-05-17 11:50:00 +00:00
|
|
|
int chatWidth;
|
2017-09-16 16:53:41 +00:00
|
|
|
int thirdWidth;
|
2017-04-09 18:06:06 +00:00
|
|
|
Adaptive::WindowLayout windowLayout;
|
|
|
|
};
|
2017-05-17 11:50:00 +00:00
|
|
|
ColumnLayout computeColumnLayout() const;
|
2017-05-13 12:02:07 +00:00
|
|
|
int dialogsSmallColumnWidth() const;
|
2017-09-19 18:59:10 +00:00
|
|
|
bool forceWideDialogs() const;
|
2017-09-16 16:53:41 +00:00
|
|
|
void updateColumnLayout();
|
|
|
|
bool canShowThirdSection() const;
|
2017-09-19 10:32:34 +00:00
|
|
|
bool canShowThirdSectionWithoutResize() const;
|
|
|
|
bool takeThirdSectionFromLayer();
|
2017-09-16 16:53:41 +00:00
|
|
|
void resizeForThirdSection();
|
|
|
|
void closeThirdSection();
|
2017-10-03 13:05:58 +00:00
|
|
|
|
2017-09-16 16:53:41 +00:00
|
|
|
void showSection(
|
|
|
|
SectionMemento &&memento,
|
2017-12-04 07:33:33 +00:00
|
|
|
const SectionShow ¶ms = SectionShow()) override;
|
2017-09-20 10:23:57 +00:00
|
|
|
void showBackFromStack(
|
2017-12-04 07:33:33 +00:00
|
|
|
const SectionShow ¶ms = SectionShow()) override;
|
2017-09-16 16:53:41 +00:00
|
|
|
|
|
|
|
void showPeerHistory(
|
|
|
|
PeerId peerId,
|
2017-10-03 17:41:44 +00:00
|
|
|
const SectionShow ¶ms = SectionShow::Way::ClearStack,
|
2017-10-03 13:05:58 +00:00
|
|
|
MsgId msgId = ShowAtUnreadMsgId);
|
2017-09-16 16:53:41 +00:00
|
|
|
void showPeerHistory(
|
|
|
|
not_null<PeerData*> peer,
|
2017-10-03 17:41:44 +00:00
|
|
|
const SectionShow ¶ms = SectionShow::Way::ClearStack,
|
2017-10-03 13:05:58 +00:00
|
|
|
MsgId msgId = ShowAtUnreadMsgId);
|
2017-09-16 16:53:41 +00:00
|
|
|
void showPeerHistory(
|
|
|
|
not_null<History*> history,
|
2017-10-03 17:41:44 +00:00
|
|
|
const SectionShow ¶ms = SectionShow::Way::ClearStack,
|
2017-10-03 13:05:58 +00:00
|
|
|
MsgId msgId = ShowAtUnreadMsgId);
|
2017-09-16 16:53:41 +00:00
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void clearSectionStack(
|
2017-10-03 13:05:58 +00:00
|
|
|
const SectionShow ¶ms = SectionShow::Way::ClearStack) {
|
2017-09-20 10:23:57 +00:00
|
|
|
showPeerHistory(
|
|
|
|
PeerId(0),
|
2017-10-03 13:05:58 +00:00
|
|
|
params,
|
|
|
|
ShowAtUnreadMsgId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void showSpecialLayer(
|
|
|
|
object_ptr<LayerWidget> &&layer,
|
|
|
|
anim::type animated = anim::type::normal);
|
|
|
|
void hideSpecialLayer(
|
|
|
|
anim::type animated = anim::type::normal) {
|
|
|
|
showSpecialLayer(nullptr, animated);
|
2017-09-20 10:23:57 +00:00
|
|
|
}
|
2017-04-09 18:06:06 +00:00
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void showJumpToDate(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
QDate requestedDate);
|
2017-08-01 11:43:50 +00:00
|
|
|
|
2017-04-09 18:06:06 +00:00
|
|
|
base::Variable<bool> &dialogsListFocused() {
|
|
|
|
return _dialogsListFocused;
|
|
|
|
}
|
2017-05-17 11:50:00 +00:00
|
|
|
const base::Variable<bool> &dialogsListFocused() const {
|
|
|
|
return _dialogsListFocused;
|
|
|
|
}
|
2017-04-09 18:06:06 +00:00
|
|
|
base::Variable<bool> &dialogsListDisplayForced() {
|
|
|
|
return _dialogsListDisplayForced;
|
|
|
|
}
|
2017-05-17 11:50:00 +00:00
|
|
|
const base::Variable<bool> &dialogsListDisplayForced() const {
|
|
|
|
return _dialogsListDisplayForced;
|
|
|
|
}
|
2017-04-09 18:06:06 +00:00
|
|
|
|
2017-12-04 07:33:33 +00:00
|
|
|
not_null<Controller*> parentController() override {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-01-21 14:49:42 +00:00
|
|
|
using RoundController = Media::Player::RoundController;
|
|
|
|
bool startRoundVideo(not_null<HistoryItem*> context);
|
|
|
|
RoundController *currentRoundVideo() const;
|
|
|
|
RoundController *roundVideo(not_null<const HistoryItem*> context) const;
|
|
|
|
RoundController *roundVideo(FullMsgId contextId) const;
|
|
|
|
void roundVideoFinished(not_null<RoundController*> video);
|
|
|
|
|
|
|
|
rpl::lifetime &lifetime() {
|
|
|
|
return _lifetime;
|
|
|
|
}
|
|
|
|
|
|
|
|
~Controller();
|
|
|
|
|
2017-03-27 12:24:38 +00:00
|
|
|
private:
|
2017-09-16 16:53:41 +00:00
|
|
|
int minimalThreeColumnWidth() const;
|
2017-09-15 17:34:41 +00:00
|
|
|
not_null<MainWidget*> chats() const;
|
2017-11-12 16:50:58 +00:00
|
|
|
int countDialogsWidthFromRatio(int bodyWidth) const;
|
|
|
|
int countThirdColumnWidthFromRatio(int bodyWidth) const;
|
|
|
|
struct ShrinkResult {
|
|
|
|
int dialogsWidth;
|
|
|
|
int thirdWidth;
|
|
|
|
};
|
|
|
|
ShrinkResult shrinkDialogsAndThirdColumns(
|
|
|
|
int dialogsWidth,
|
|
|
|
int thirdWidth,
|
|
|
|
int bodyWidth) const;
|
2017-09-15 17:34:41 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<MainWindow*> _window;
|
2017-04-07 18:10:49 +00:00
|
|
|
|
2017-08-31 16:28:58 +00:00
|
|
|
GifPauseReasons _gifPauseReasons = 0;
|
2017-04-07 18:10:49 +00:00
|
|
|
base::Observable<void> _gifPauseLevelChanged;
|
2017-05-23 14:04:59 +00:00
|
|
|
base::Observable<void> _floatPlayerAreaUpdated;
|
2017-04-07 18:10:49 +00:00
|
|
|
|
2018-01-22 16:42:25 +00:00
|
|
|
rpl::variable<Dialogs::RowDescriptor> _activeChatEntry;
|
2017-04-09 18:06:06 +00:00
|
|
|
base::Variable<bool> _dialogsListFocused = { false };
|
|
|
|
base::Variable<bool> _dialogsListDisplayForced = { false };
|
|
|
|
|
2018-01-21 14:49:42 +00:00
|
|
|
std::unique_ptr<RoundController> _roundVideo;
|
|
|
|
|
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2017-03-27 12:24:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Window
|