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

124 lines
2.9 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"
2023-12-05 17:25:26 +04:00
#include "base/unique_qptr.h"
2023-12-04 15:48:17 +04:00
#include "ui/effects/animations.h"
#include "ui/text/text.h"
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;
} // namespace Ui
namespace Iv {
struct Prepared;
class Controller final {
public:
Controller();
~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,
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-07 14:37:58 +04:00
[[nodiscard]] bool showFast(const QString &url, const QString &hash);
2023-12-04 23:06:44 +04:00
void show(
const QString &dataPath,
Prepared page,
base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues);
2024-03-11 16:59:11 +04:00
void update(Prepared page);
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();
2023-12-07 14:37:58 +04:00
void createWebview(const QString &dataPath);
[[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
2023-12-04 15:48:17 +04:00
void updateTitleGeometry();
void paintTitle(Painter &p, QRect clip);
2023-12-07 14:37:58 +04:00
void showInWindow(const QString &dataPath, 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);
2023-12-07 14:37:58 +04:00
void menu(int index, const QString &hash);
2023-12-01 18:47:24 +04:00
void escape();
void close();
void quit();
std::unique_ptr<Ui::RpWindow> _window;
2023-12-04 15:48:17 +04:00
std::unique_ptr<Ui::RpWidget> _title;
2023-12-05 17:25:26 +04:00
base::unique_qptr<Ui::PopupMenu> _menu;
2023-12-04 15:48:17 +04:00
Ui::Text::String _titleText;
int _titleLeftSkip = 0;
int _titleRightSkip = 0;
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;
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