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

107 lines
2.3 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-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;
} // 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-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(
const QString &dataPath,
Prepared page,
base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues);
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-04 15:48:17 +04:00
void updateTitleGeometry();
void paintTitle(Painter &p, QRect clip);
2023-12-04 23:06:44 +04:00
void showInWindow(
const QString &dataPath,
Prepared page,
const QByteArray &initScript);
[[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-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;
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;
SingleQueuedInvokation _updateStyles;
bool _subscribedToColors = false;
2023-12-04 23:06:44 +04:00
bool _ready = false;
rpl::lifetime _lifetime;
};
} // namespace Iv