2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-23 10:47:11 +00:00
tdesktop/Telegram/SourceFiles/iv/iv_controller.h

175 lines
4.4 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 "base/invoke_queued.h"
#include "base/object_ptr.h"
2023-12-05 17:25:26 +04:00
#include "base/unique_qptr.h"
2024-03-23 12:42:22 +04:00
#include "iv/iv_delegate.h"
2023-12-04 15:48:17 +04:00
#include "ui/effects/animations.h"
#include "ui/text/text.h"
2024-04-25 15:34:00 +04:00
#include "webview/webview_common.h"
2023-12-04 15:48:17 +04:00
class Painter;
namespace Webview {
struct DataRequest;
class Window;
} // namespace Webview
namespace Ui {
class RpWidget;
class RpWindow;
2023-12-05 17:25:26 +04:00
class PopupMenu;
class FlatLabel;
class IconButton;
template <typename Widget>
class FadeWrapScaled;
} // namespace Ui
namespace Iv {
struct Prepared;
struct ShareBoxResult {
Fn<void()> focus;
Fn<void()> hide;
rpl::producer<> destroyRequests;
};
struct ShareBoxDescriptor {
not_null<Ui::RpWidget*> parent;
QString url;
};
class Controller final {
public:
2024-03-23 12:42:22 +04:00
Controller(
not_null<Delegate*> delegate,
Fn<ShareBoxResult(ShareBoxDescriptor)> showShareBox);
~Controller();
2023-12-04 23:06:44 +04:00
struct Event {
enum class Type {
Close,
Quit,
OpenChannel,
JoinChannel,
2023-12-05 13:17:07 +04:00
OpenPage,
2023-12-05 11:54:46 +04:00
OpenLink,
2023-12-05 17:25:26 +04:00
OpenLinkExternal,
2024-02-13 11:53:40 +04:00
OpenMedia,
2024-04-26 19:20:43 +04:00
Report,
2023-12-04 23:06:44 +04:00
};
Type type = Type::Close;
2023-12-05 13:17:07 +04:00
QString url;
2023-12-04 23:06:44 +04:00
QString context;
2023-12-01 18:47:24 +04:00
};
2023-12-04 23:06:44 +04:00
void show(
2024-04-25 15:34:00 +04:00
const Webview::StorageId &storageId,
2023-12-04 23:06:44 +04:00
Prepared page,
base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues);
2024-03-11 16:59:11 +04:00
void update(Prepared page);
[[nodiscard]] static bool IsGoodTonSiteUrl(const QString &uri);
2024-07-26 19:25:47 +02:00
void showTonSite(const Webview::StorageId &storageId, QString uri);
2023-12-01 18:47:24 +04:00
[[nodiscard]] bool active() const;
2023-12-04 23:06:44 +04:00
void showJoinedTooltip();
2023-12-01 18:47:24 +04:00
void minimize();
[[nodiscard]] rpl::producer<Webview::DataRequest> dataRequests() const {
return _dataRequests.events();
}
2023-12-01 18:47:24 +04:00
[[nodiscard]] rpl::producer<Event> events() const {
return _events.events();
}
[[nodiscard]] rpl::lifetime &lifetime();
private:
void createWindow();
2024-04-25 15:34:00 +04:00
void createWebview(const Webview::StorageId &storageId);
2023-12-07 14:37:58 +04:00
[[nodiscard]] QByteArray navigateScript(int index, const QString &hash);
2024-03-11 16:59:11 +04:00
[[nodiscard]] QByteArray reloadScript(int index);
2023-12-07 14:37:58 +04:00
2024-04-25 15:34:00 +04:00
void showInWindow(const Webview::StorageId &storageId, Prepared page);
2023-12-04 23:06:44 +04:00
[[nodiscard]] QByteArray fillInChannelValuesScript(
base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues);
[[nodiscard]] QByteArray toggleInChannelScript(
const QByteArray &id,
bool in) const;
void processKey(const QString &key, const QString &modifier);
void processLink(const QString &url, const QString &context);
void initControls();
void updateTitleGeometry(int newWidth) const;
void activate();
void setInnerFocus();
void showMenu();
2023-12-01 18:47:24 +04:00
void escape();
void close();
void quit();
[[nodiscard]] QString composeCurrentUrl() const;
2024-04-26 19:20:43 +04:00
[[nodiscard]] uint64 compuseCurrentPageId() const;
void showShareMenu();
void destroyShareMenu();
2024-07-30 15:53:06 +02:00
void showWebviewError();
void showWebviewError(TextWithEntities text);
2024-03-23 12:42:22 +04:00
const not_null<Delegate*> _delegate;
std::unique_ptr<Ui::RpWindow> _window;
std::unique_ptr<Ui::RpWidget> _subtitleWrap;
rpl::variable<QString> _url;
rpl::variable<QString> _subtitleText;
2024-08-01 14:47:33 +02:00
rpl::variable<QString> _windowTitleText;
std::unique_ptr<Ui::FlatLabel> _subtitle;
Ui::Animations::Simple _subtitleBackShift;
Ui::Animations::Simple _subtitleForwardShift;
object_ptr<Ui::IconButton> _menuToggle = { nullptr };
object_ptr<Ui::FadeWrapScaled<Ui::IconButton>> _back = { nullptr };
object_ptr<Ui::FadeWrapScaled<Ui::IconButton>> _forward = { nullptr };
2023-12-05 17:25:26 +04:00
base::unique_qptr<Ui::PopupMenu> _menu;
Ui::RpWidget *_container = nullptr;
std::unique_ptr<Webview::Window> _webview;
rpl::event_stream<Webview::DataRequest> _dataRequests;
2023-12-01 18:47:24 +04:00
rpl::event_stream<Event> _events;
2023-12-04 23:06:44 +04:00
base::flat_map<QByteArray, bool> _inChannelChanged;
2023-12-07 14:37:58 +04:00
base::flat_set<QByteArray> _inChannelSubscribed;
SingleQueuedInvokation _updateStyles;
2024-03-11 16:59:11 +04:00
bool _reloadInitialWhenReady = false;
bool _subscribedToColors = false;
2023-12-04 23:06:44 +04:00
bool _ready = false;
rpl::variable<int> _index = -1;
QString _hash;
Fn<ShareBoxResult(ShareBoxDescriptor)> _showShareBox;
std::unique_ptr<Ui::RpWidget> _shareWrap;
std::unique_ptr<QWidget> _shareContainer;
Fn<void()> _shareFocus;
Fn<void()> _shareHide;
bool _shareHidesContent = false;
2023-12-07 14:37:58 +04:00
std::vector<Prepared> _pages;
base::flat_map<QString, int> _indices;
QString _navigateToHashWhenReady;
int _navigateToIndexWhenReady = -1;
rpl::lifetime _lifetime;
};
} // namespace Iv