mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Moved out significant part of url auth box to td_ui.
This commit is contained in:
@@ -814,6 +814,13 @@ urlAuthCheckboxAbout: FlatLabel(defaultPeerListAbout) {
|
||||
font: font(12px);
|
||||
}
|
||||
}
|
||||
urlAuthBoxRowTopLabel: FlatLabel(boxLabel) {
|
||||
maxHeight: 30px;
|
||||
}
|
||||
urlAuthBoxRowBottomLabel: FlatLabel(defaultFlatLabel) {
|
||||
textFg: windowSubTextFg;
|
||||
maxHeight: 30px;
|
||||
}
|
||||
|
||||
addContactFieldMargin: margins(19px, 0px, 19px, 10px);
|
||||
addContactWarningMargin: margins(19px, 10px, 19px, 5px);
|
||||
|
||||
@@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "boxes/url_auth_box.h"
|
||||
|
||||
#include "apiwrap.h"
|
||||
#include "base/qthelp_url.h"
|
||||
#include "boxes/url_auth_box_content.h"
|
||||
#include "core/application.h"
|
||||
#include "core/click_handler_types.h"
|
||||
#include "data/data_peer.h"
|
||||
@@ -22,135 +22,20 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_domain.h"
|
||||
#include "main/main_session.h"
|
||||
#include "send_credits_box.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "ui/controls/userpic_button.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/userpic_view.h"
|
||||
#include "ui/vertical_list.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/widgets/menu/menu_action.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_settings.h"
|
||||
#include "styles/style_premium.h"
|
||||
#include "styles/style_window.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
|
||||
namespace UrlAuthBox {
|
||||
namespace {
|
||||
|
||||
class SwitchableUserpicButton final : public Ui::RippleButton {
|
||||
public:
|
||||
SwitchableUserpicButton(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<UserData*> peer,
|
||||
int size);
|
||||
|
||||
void setExpanded(bool expanded);
|
||||
[[nodiscard]] bool isExpanded() const {
|
||||
return _expanded;
|
||||
}
|
||||
|
||||
void setUser(not_null<UserData*> user);
|
||||
[[nodiscard]] not_null<UserData*> user() const {
|
||||
return _user;
|
||||
}
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
QImage prepareRippleMask() const override;
|
||||
QPoint prepareRippleStartPosition() const override;
|
||||
|
||||
const int _size;
|
||||
const int _userpicSize;
|
||||
const int _skip;
|
||||
bool _expanded = false;
|
||||
not_null<UserData*> _user;
|
||||
base::unique_qptr<Ui::UserpicButton> _userpic;
|
||||
|
||||
};
|
||||
|
||||
SwitchableUserpicButton::SwitchableUserpicButton(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<UserData*> peer,
|
||||
int size)
|
||||
: RippleButton(parent, st::defaultRippleAnimation)
|
||||
, _size(size)
|
||||
, _userpicSize(st::restoreUserpicIcon.photoSize)
|
||||
, _skip((_size - _userpicSize) / 2)
|
||||
, _user(peer)
|
||||
, _userpic(base::make_unique_q<Ui::UserpicButton>(
|
||||
this,
|
||||
peer,
|
||||
st::restoreUserpicIcon)) {
|
||||
resize(_size, _size);
|
||||
_userpic->move(_skip, _skip);
|
||||
_userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
}
|
||||
|
||||
void SwitchableUserpicButton::setUser(not_null<UserData*> user) {
|
||||
if (_user == user) {
|
||||
return;
|
||||
}
|
||||
_user = user;
|
||||
_userpic = base::make_unique_q<Ui::UserpicButton>(
|
||||
this,
|
||||
user,
|
||||
st::restoreUserpicIcon);
|
||||
_userpic->moveToRight(_skip, _skip);
|
||||
_userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
_userpic->show();
|
||||
update();
|
||||
}
|
||||
|
||||
void SwitchableUserpicButton::setExpanded(bool expanded) {
|
||||
if (_expanded == expanded) {
|
||||
return;
|
||||
}
|
||||
_expanded = expanded;
|
||||
const auto w = _expanded
|
||||
? (_size * 2.5 - _userpicSize)
|
||||
: _size;
|
||||
resize(w, _size);
|
||||
_userpic->moveToRight(_skip, _skip);
|
||||
update();
|
||||
}
|
||||
|
||||
void SwitchableUserpicButton::paintEvent(QPaintEvent *e) {
|
||||
auto p = QPainter(this);
|
||||
paintRipple(p, 0, 0);
|
||||
|
||||
if (!_expanded) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto arrowSize = st::lineWidth * 12;
|
||||
const auto center = QPoint(_size / 2, height() / 2 + st::lineWidth * 4);
|
||||
|
||||
auto pen = QPen(st::windowSubTextFg);
|
||||
pen.setWidthF(st::lineWidth * 1.5);
|
||||
p.setPen(pen);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
p.drawLine(center, center + QPoint(-arrowSize / 2, -arrowSize / 2));
|
||||
p.drawLine(center, center + QPoint(arrowSize / 2, -arrowSize / 2));
|
||||
}
|
||||
|
||||
QImage SwitchableUserpicButton::prepareRippleMask() const {
|
||||
return _expanded
|
||||
? Ui::RippleAnimation::RoundRectMask(size(), height() / 2)
|
||||
: Ui::RippleAnimation::EllipseMask(size());
|
||||
}
|
||||
|
||||
QPoint SwitchableUserpicButton::prepareRippleStartPosition() const {
|
||||
return mapFromGlobal(QCursor::pos());
|
||||
}
|
||||
|
||||
using AnotherSessionFactory = Fn<not_null<Main::Session*>()>;
|
||||
|
||||
struct SwitchAccountResult {
|
||||
@@ -163,14 +48,24 @@ struct SwitchAccountResult {
|
||||
const auto session = &Core::App().domain().active().session();
|
||||
const auto widget = Ui::CreateChild<SwitchableUserpicButton>(
|
||||
parent,
|
||||
session->user(),
|
||||
st::restoreUserpicIcon.photoSize + st::lineWidth * 8);
|
||||
struct State {
|
||||
base::unique_qptr<Ui::PopupMenu> menu;
|
||||
UserData *currentUser = nullptr;
|
||||
};
|
||||
const auto state = widget->lifetime().make_state<State>();
|
||||
state->currentUser = session->user();
|
||||
const auto userpic = Ui::CreateChild<Ui::UserpicButton>(
|
||||
parent,
|
||||
state->currentUser,
|
||||
st::restoreUserpicIcon);
|
||||
widget->setUserpic(userpic);
|
||||
const auto isCurrentTest = session->isTestMode();
|
||||
const auto filtered = [=] {
|
||||
auto result = std::vector<not_null<Main::Session*>>();
|
||||
for (const auto &account : Core::App().domain().orderedAccounts()) {
|
||||
if (!account->sessionExists()
|
||||
|| (account->session().user() == widget->user())
|
||||
|| (account->session().user() == state->currentUser)
|
||||
|| (account->session().isTestMode() != isCurrentTest)) {
|
||||
continue;
|
||||
}
|
||||
@@ -181,10 +76,6 @@ struct SwitchAccountResult {
|
||||
const auto isSingle = filtered().empty();
|
||||
widget->setExpanded(!isSingle);
|
||||
widget->setAttribute(Qt::WA_TransparentForMouseEvents, isSingle);
|
||||
struct State {
|
||||
base::unique_qptr<Ui::PopupMenu> menu;
|
||||
};
|
||||
const auto state = widget->lifetime().make_state<State>();
|
||||
widget->setClickedCallback([=] {
|
||||
const auto &st = st::popupMenuWithIcons;
|
||||
state->menu = base::make_unique_q<Ui::PopupMenu>(widget, st);
|
||||
@@ -192,7 +83,12 @@ struct SwitchAccountResult {
|
||||
const auto user = anotherSession->user();
|
||||
const auto action = new QAction(user->name(), state->menu);
|
||||
QObject::connect(action, &QAction::triggered, [=] {
|
||||
widget->setUser(user);
|
||||
state->currentUser = user;
|
||||
const auto newUserpic = Ui::CreateChild<Ui::UserpicButton>(
|
||||
parent,
|
||||
user,
|
||||
st::restoreUserpicIcon);
|
||||
widget->setUserpic(newUserpic);
|
||||
});
|
||||
auto owned = base::make_unique_q<Ui::Menu::Action>(
|
||||
state->menu->menu(),
|
||||
@@ -200,12 +96,12 @@ struct SwitchAccountResult {
|
||||
action,
|
||||
nullptr,
|
||||
nullptr);
|
||||
const auto userpic = Ui::CreateChild<Ui::UserpicButton>(
|
||||
const auto menuUserpic = Ui::CreateChild<Ui::UserpicButton>(
|
||||
owned.get(),
|
||||
user,
|
||||
st::lockSetupEmailUserpicSmall);
|
||||
userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
userpic->move(st.menu.itemIconPosition);
|
||||
menuUserpic->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
menuUserpic->move(st.menu.itemIconPosition);
|
||||
state->menu->addAction(std::move(owned));
|
||||
}
|
||||
|
||||
@@ -218,68 +114,10 @@ struct SwitchAccountResult {
|
||||
});
|
||||
return {
|
||||
widget,
|
||||
[=] { return &widget->user()->session(); },
|
||||
[=] { return &state->currentUser->session(); },
|
||||
};
|
||||
}
|
||||
|
||||
void AddAuthInfoRow(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
const QString &topText,
|
||||
const QString &bottomText,
|
||||
const QString &leftText,
|
||||
const style::icon &icon) {
|
||||
const auto row = container->add(
|
||||
object_ptr<Ui::RpWidget>(container),
|
||||
st::boxRowPadding);
|
||||
|
||||
const auto topLabel = Ui::CreateChild<Ui::FlatLabel>(
|
||||
row,
|
||||
topText,
|
||||
st::boxLabel);
|
||||
const auto bottomLabel = Ui::CreateChild<Ui::FlatLabel>(
|
||||
row,
|
||||
bottomText,
|
||||
st::sessionValueLabel);
|
||||
const auto leftLabel = Ui::CreateChild<Ui::FlatLabel>(
|
||||
row,
|
||||
leftText,
|
||||
st::boxLabel);
|
||||
|
||||
rpl::combine(
|
||||
row->widthValue(),
|
||||
topLabel->sizeValue(),
|
||||
bottomLabel->sizeValue()
|
||||
) | rpl::on_next([=](int rowWidth, QSize topSize, QSize bottomSize) {
|
||||
const auto totalHeight = topSize.height() + bottomSize.height();
|
||||
row->resize(rowWidth, totalHeight);
|
||||
|
||||
topLabel->moveToRight(0, 0);
|
||||
bottomLabel->moveToRight(0, topSize.height());
|
||||
|
||||
const auto left = st::sessionValuePadding.left();
|
||||
leftLabel->moveToLeft(left, (totalHeight - leftLabel->height()) / 2);
|
||||
}, row->lifetime());
|
||||
|
||||
{
|
||||
const auto widget = Ui::CreateChild<Ui::RpWidget>(row);
|
||||
widget->resize(icon.size());
|
||||
|
||||
rpl::combine(
|
||||
row->widthValue(),
|
||||
topLabel->sizeValue(),
|
||||
bottomLabel->sizeValue()
|
||||
) | rpl::on_next([=](int rowWidth, QSize topSize, QSize bottomSize) {
|
||||
const auto totalHeight = topSize.height() + bottomSize.height();
|
||||
widget->moveToLeft(0, (totalHeight - leftLabel->height()) / 2);
|
||||
}, row->lifetime());
|
||||
|
||||
widget->paintRequest() | rpl::on_next([=, &icon] {
|
||||
auto p = QPainter(widget);
|
||||
icon.paintInCenter(p, widget->rect());
|
||||
}, widget->lifetime());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void RequestButton(
|
||||
@@ -295,25 +133,6 @@ void RequestUrl(
|
||||
const QString &url,
|
||||
QVariant context);
|
||||
|
||||
void Show(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Main::Session*> session,
|
||||
const QString &url,
|
||||
const QString &domain,
|
||||
UserData *bot,
|
||||
Fn<void(Result)> callback);
|
||||
void ShowDetails(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Main::Session*> session,
|
||||
const QString &url,
|
||||
const QString &domain,
|
||||
Fn<void(Result)> callback,
|
||||
UserData *bot,
|
||||
const QString &browser,
|
||||
const QString &platform,
|
||||
const QString &ip,
|
||||
const QString ®ion);
|
||||
|
||||
void ActivateButton(
|
||||
std::shared_ptr<Ui::Show> show,
|
||||
not_null<const HistoryItem*> message,
|
||||
@@ -471,7 +290,13 @@ void RequestButton(
|
||||
}
|
||||
};
|
||||
*box = show->show(
|
||||
Box(Show, session, url, qs(request.vdomain()), bot, callback),
|
||||
Box(
|
||||
Show,
|
||||
url,
|
||||
qs(request.vdomain()),
|
||||
session->user()->name(),
|
||||
bot->firstName,
|
||||
callback),
|
||||
Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
@@ -573,11 +398,15 @@ void RequestUrl(
|
||||
};
|
||||
ShowDetails(
|
||||
box,
|
||||
session,
|
||||
url,
|
||||
domain,
|
||||
callback,
|
||||
bot,
|
||||
object_ptr<Ui::UserpicButton>(
|
||||
box->verticalLayout(),
|
||||
bot,
|
||||
st::defaultUserpicButton,
|
||||
Ui::PeerUserpicShape::Forum),
|
||||
Info::Profile::NameValue(bot),
|
||||
browser,
|
||||
device,
|
||||
ip,
|
||||
@@ -592,184 +421,4 @@ void RequestUrl(
|
||||
}));
|
||||
}
|
||||
|
||||
void Show(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Main::Session*> session,
|
||||
const QString &url,
|
||||
const QString &domain,
|
||||
UserData *bot,
|
||||
Fn<void(Result)> callback) {
|
||||
box->setWidth(st::boxWidth);
|
||||
|
||||
box->addRow(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
box,
|
||||
tr::lng_url_auth_open_confirm(tr::now, lt_link, url),
|
||||
st::boxLabel),
|
||||
st::boxPadding);
|
||||
|
||||
const auto addCheckbox = [&](const TextWithEntities &text) {
|
||||
const auto checkbox = box->addRow(
|
||||
object_ptr<Ui::Checkbox>(
|
||||
box,
|
||||
text,
|
||||
true,
|
||||
st::urlAuthCheckbox),
|
||||
style::margins(
|
||||
st::boxPadding.left(),
|
||||
st::boxPadding.bottom(),
|
||||
st::boxPadding.right(),
|
||||
st::boxPadding.bottom()));
|
||||
checkbox->setAllowTextLines();
|
||||
return checkbox;
|
||||
};
|
||||
|
||||
const auto auth = addCheckbox(
|
||||
tr::lng_url_auth_login_option(
|
||||
tr::now,
|
||||
lt_domain,
|
||||
tr::bold(domain),
|
||||
lt_user,
|
||||
tr::bold(session->user()->name()),
|
||||
tr::marked));
|
||||
|
||||
const auto allow = bot
|
||||
? addCheckbox(tr::lng_url_auth_allow_messages(
|
||||
tr::now,
|
||||
lt_bot,
|
||||
tr::bold(bot->firstName),
|
||||
tr::marked))
|
||||
: nullptr;
|
||||
|
||||
if (allow) {
|
||||
rpl::single(
|
||||
auth->checked()
|
||||
) | rpl::then(
|
||||
auth->checkedChanges()
|
||||
) | rpl::on_next([=](bool checked) {
|
||||
if (!checked) {
|
||||
allow->setChecked(false);
|
||||
}
|
||||
allow->setDisabled(!checked);
|
||||
}, auth->lifetime());
|
||||
}
|
||||
|
||||
box->addButton(tr::lng_open_link(), [=] {
|
||||
const auto authed = auth->checked();
|
||||
const auto allowed = (authed && allow && allow->checked());
|
||||
callback({
|
||||
.auth = authed,
|
||||
.allowWrite = allowed,
|
||||
});
|
||||
});
|
||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||
}
|
||||
|
||||
void ShowDetails(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Main::Session*> session,
|
||||
const QString &url,
|
||||
const QString &domain,
|
||||
Fn<void(Result)> callback,
|
||||
UserData *bot,
|
||||
const QString &browser,
|
||||
const QString &platform,
|
||||
const QString &ip,
|
||||
const QString ®ion) {
|
||||
box->setWidth(st::boxWidth);
|
||||
|
||||
const auto content = box->verticalLayout();
|
||||
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
if (bot) {
|
||||
const auto userpic = content->add(
|
||||
object_ptr<Ui::UserpicButton>(
|
||||
content,
|
||||
bot,
|
||||
st::defaultUserpicButton,
|
||||
Ui::PeerUserpicShape::Forum),
|
||||
st::boxRowPadding,
|
||||
style::al_top);
|
||||
userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
}
|
||||
|
||||
const auto domainUrl = qthelp::validate_url(domain);
|
||||
content->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
content,
|
||||
domainUrl.isEmpty()
|
||||
? tr::lng_url_auth_login_button(tr::marked)
|
||||
: tr::lng_url_auth_login_title(
|
||||
lt_domain,
|
||||
rpl::single(Ui::Text::Link(domain, domainUrl)),
|
||||
tr::marked),
|
||||
st::boxTitle),
|
||||
st::boxRowPadding,
|
||||
style::al_top);
|
||||
Ui::AddSkip(content);
|
||||
|
||||
content->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
content,
|
||||
tr::lng_url_auth_site_access(tr::rich),
|
||||
st::urlAuthCheckboxAbout),
|
||||
st::boxRowPadding);
|
||||
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
if (!platform.isEmpty() || !browser.isEmpty()) {
|
||||
AddAuthInfoRow(
|
||||
content,
|
||||
platform,
|
||||
browser,
|
||||
tr::lng_url_auth_device_label(tr::now),
|
||||
st::menuIconDevices);
|
||||
}
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
|
||||
if (!ip.isEmpty() || !region.isEmpty()) {
|
||||
AddAuthInfoRow(
|
||||
content,
|
||||
ip,
|
||||
region,
|
||||
tr::lng_url_auth_ip_label(tr::now),
|
||||
st::menuIconAddress);
|
||||
}
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
|
||||
Ui::AddDividerText(
|
||||
content,
|
||||
rpl::single(tr::lng_url_auth_login_attempt(tr::now)));
|
||||
Ui::AddSkip(content);
|
||||
|
||||
auto allowMessages = (Ui::SettingsButton*)(nullptr);
|
||||
if (bot) {
|
||||
allowMessages = content->add(
|
||||
object_ptr<Ui::SettingsButton>(
|
||||
content,
|
||||
tr::lng_url_auth_allow_messages_label()));
|
||||
allowMessages->toggleOn(rpl::single(false));
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddDividerText(
|
||||
content,
|
||||
tr::lng_url_auth_allow_messages_about(
|
||||
lt_bot,
|
||||
Info::Profile::NameValue(bot)));
|
||||
Ui::AddSkip(content);
|
||||
}
|
||||
|
||||
box->addButton(tr::lng_url_auth_login_button(), [=] {
|
||||
callback({
|
||||
.auth = true,
|
||||
.allowWrite = (allowMessages && allowMessages->toggled()),
|
||||
});
|
||||
});
|
||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||
}
|
||||
|
||||
} // namespace UrlAuthBox
|
||||
|
||||
@@ -21,12 +21,6 @@ class Show;
|
||||
|
||||
namespace UrlAuthBox {
|
||||
|
||||
struct Result {
|
||||
bool auth : 1 = false;
|
||||
bool allowWrite : 1 = false;
|
||||
bool sharePhone : 1 = false;
|
||||
};
|
||||
|
||||
void ActivateButton(
|
||||
std::shared_ptr<Ui::Show> show,
|
||||
not_null<const HistoryItem*> message,
|
||||
|
||||
@@ -0,0 +1,331 @@
|
||||
/*
|
||||
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
|
||||
*/
|
||||
#include "boxes/url_auth_box_content.h"
|
||||
|
||||
#include "base/qthelp_url.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "ui/vertical_list.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
#include "styles/style_settings.h"
|
||||
|
||||
namespace UrlAuthBox {
|
||||
|
||||
SwitchableUserpicButton::SwitchableUserpicButton(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
int size)
|
||||
: RippleButton(parent, st::defaultRippleAnimation)
|
||||
, _size(size)
|
||||
, _userpicSize(st::restoreUserpicIcon.photoSize)
|
||||
, _skip((_size - _userpicSize) / 2) {
|
||||
resize(_size, _size);
|
||||
}
|
||||
|
||||
void SwitchableUserpicButton::setUserpic(not_null<Ui::RpWidget*> userpic) {
|
||||
_userpic = userpic;
|
||||
_userpic->setParent(this);
|
||||
_userpic->moveToRight(_skip, _skip);
|
||||
_userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
_userpic->show();
|
||||
update();
|
||||
}
|
||||
|
||||
void SwitchableUserpicButton::setExpanded(bool expanded) {
|
||||
if (_expanded == expanded) {
|
||||
return;
|
||||
}
|
||||
_expanded = expanded;
|
||||
const auto w = _expanded
|
||||
? (_size * 2.5 - _userpicSize)
|
||||
: _size;
|
||||
resize(w, _size);
|
||||
if (_userpic) {
|
||||
_userpic->moveToRight(_skip, _skip);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void SwitchableUserpicButton::paintEvent(QPaintEvent *e) {
|
||||
auto p = QPainter(this);
|
||||
paintRipple(p, 0, 0);
|
||||
|
||||
if (!_expanded) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto arrowSize = st::lineWidth * 10;
|
||||
const auto center = QPoint(_size / 2, height() / 2 + st::lineWidth * 3);
|
||||
|
||||
auto pen = QPen(st::windowSubTextFg);
|
||||
pen.setWidthF(st::lineWidth * 1.5);
|
||||
p.setPen(pen);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
p.drawLine(center, center + QPoint(-arrowSize / 2, -arrowSize / 2));
|
||||
p.drawLine(center, center + QPoint(arrowSize / 2, -arrowSize / 2));
|
||||
}
|
||||
|
||||
QImage SwitchableUserpicButton::prepareRippleMask() const {
|
||||
return _expanded
|
||||
? Ui::RippleAnimation::RoundRectMask(size(), height() / 2)
|
||||
: Ui::RippleAnimation::EllipseMask(size());
|
||||
}
|
||||
|
||||
QPoint SwitchableUserpicButton::prepareRippleStartPosition() const {
|
||||
return mapFromGlobal(QCursor::pos());
|
||||
}
|
||||
|
||||
void AddAuthInfoRow(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
const QString &topText,
|
||||
const QString &bottomText,
|
||||
const QString &leftText,
|
||||
const style::icon &icon) {
|
||||
const auto row = container->add(
|
||||
object_ptr<Ui::RpWidget>(container),
|
||||
st::boxRowPadding);
|
||||
|
||||
const auto topLabel = Ui::CreateChild<Ui::FlatLabel>(
|
||||
row,
|
||||
topText,
|
||||
st::urlAuthBoxRowTopLabel);
|
||||
const auto bottomLabel = Ui::CreateChild<Ui::FlatLabel>(
|
||||
row,
|
||||
bottomText,
|
||||
st::urlAuthBoxRowBottomLabel);
|
||||
const auto leftLabel = Ui::CreateChild<Ui::FlatLabel>(
|
||||
row,
|
||||
leftText,
|
||||
st::boxLabel);
|
||||
|
||||
rpl::combine(
|
||||
row->widthValue(),
|
||||
topLabel->sizeValue(),
|
||||
bottomLabel->sizeValue()
|
||||
) | rpl::on_next([=](int rowWidth, QSize topSize, QSize bottomSize) {
|
||||
const auto totalHeight = topSize.height() + bottomSize.height();
|
||||
row->resize(rowWidth, totalHeight);
|
||||
|
||||
const auto left = st::sessionValuePadding.left();
|
||||
const auto availableWidth = rowWidth
|
||||
- leftLabel->width()
|
||||
- left
|
||||
- st::defaultVerticalListSkip;
|
||||
|
||||
topLabel->resizeToNaturalWidth(availableWidth);
|
||||
topLabel->moveToRight(0, 0);
|
||||
bottomLabel->resizeToNaturalWidth(availableWidth);
|
||||
bottomLabel->moveToRight(0, topSize.height());
|
||||
;
|
||||
leftLabel->moveToLeft(left, (totalHeight - leftLabel->height()) / 2);
|
||||
}, row->lifetime());
|
||||
|
||||
{
|
||||
const auto widget = Ui::CreateChild<Ui::RpWidget>(row);
|
||||
widget->resize(icon.size());
|
||||
|
||||
rpl::combine(
|
||||
row->widthValue(),
|
||||
topLabel->sizeValue(),
|
||||
bottomLabel->sizeValue()
|
||||
) | rpl::on_next([=](int rowWidth, QSize topSize, QSize bottomSize) {
|
||||
const auto totalHeight = topSize.height() + bottomSize.height();
|
||||
widget->moveToLeft(0, (totalHeight - leftLabel->height()) / 2);
|
||||
}, row->lifetime());
|
||||
|
||||
widget->paintRequest() | rpl::on_next([=, &icon] {
|
||||
auto p = QPainter(widget);
|
||||
icon.paintInCenter(p, widget->rect());
|
||||
}, widget->lifetime());
|
||||
}
|
||||
}
|
||||
|
||||
void Show(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
const QString &url,
|
||||
const QString &domain,
|
||||
const QString &selfName,
|
||||
const QString &botName,
|
||||
Fn<void(Result)> callback) {
|
||||
box->setWidth(st::boxWidth);
|
||||
|
||||
box->addRow(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
box,
|
||||
tr::lng_url_auth_open_confirm(tr::now, lt_link, url),
|
||||
st::boxLabel),
|
||||
st::boxPadding);
|
||||
|
||||
const auto addCheckbox = [&](const TextWithEntities &text) {
|
||||
const auto checkbox = box->addRow(
|
||||
object_ptr<Ui::Checkbox>(
|
||||
box,
|
||||
text,
|
||||
true,
|
||||
st::urlAuthCheckbox),
|
||||
style::margins(
|
||||
st::boxPadding.left(),
|
||||
st::boxPadding.bottom(),
|
||||
st::boxPadding.right(),
|
||||
st::boxPadding.bottom()));
|
||||
checkbox->setAllowTextLines();
|
||||
return checkbox;
|
||||
};
|
||||
|
||||
const auto auth = addCheckbox(
|
||||
tr::lng_url_auth_login_option(
|
||||
tr::now,
|
||||
lt_domain,
|
||||
tr::bold(domain),
|
||||
lt_user,
|
||||
tr::bold(selfName),
|
||||
tr::marked));
|
||||
|
||||
const auto allow = !botName.isEmpty()
|
||||
? addCheckbox(tr::lng_url_auth_allow_messages(
|
||||
tr::now,
|
||||
lt_bot,
|
||||
tr::bold(botName),
|
||||
tr::marked))
|
||||
: nullptr;
|
||||
|
||||
if (allow) {
|
||||
rpl::single(
|
||||
auth->checked()
|
||||
) | rpl::then(
|
||||
auth->checkedChanges()
|
||||
) | rpl::on_next([=](bool checked) {
|
||||
if (!checked) {
|
||||
allow->setChecked(false);
|
||||
}
|
||||
allow->setDisabled(!checked);
|
||||
}, auth->lifetime());
|
||||
}
|
||||
|
||||
box->addButton(tr::lng_open_link(), [=] {
|
||||
const auto authed = auth->checked();
|
||||
const auto allowed = (authed && allow && allow->checked());
|
||||
callback({
|
||||
.auth = authed,
|
||||
.allowWrite = allowed,
|
||||
});
|
||||
});
|
||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||
}
|
||||
|
||||
void ShowDetails(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
const QString &url,
|
||||
const QString &domain,
|
||||
Fn<void(Result)> callback,
|
||||
object_ptr<Ui::RpWidget> userpicOwned,
|
||||
rpl::producer<QString> botName,
|
||||
const QString &browser,
|
||||
const QString &platform,
|
||||
const QString &ip,
|
||||
const QString ®ion) {
|
||||
box->setWidth(st::boxWidth);
|
||||
|
||||
const auto content = box->verticalLayout();
|
||||
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
if (userpicOwned) {
|
||||
const auto userpic = content->add(
|
||||
std::move(userpicOwned),
|
||||
st::boxRowPadding,
|
||||
style::al_top);
|
||||
userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
}
|
||||
|
||||
const auto domainUrl = qthelp::validate_url(domain);
|
||||
content->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
content,
|
||||
domainUrl.isEmpty()
|
||||
? tr::lng_url_auth_login_button(tr::marked)
|
||||
: tr::lng_url_auth_login_title(
|
||||
lt_domain,
|
||||
rpl::single(Ui::Text::Link(domain, domainUrl)),
|
||||
tr::marked),
|
||||
st::boxTitle),
|
||||
st::boxRowPadding,
|
||||
style::al_top);
|
||||
Ui::AddSkip(content);
|
||||
|
||||
content->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
content,
|
||||
tr::lng_url_auth_site_access(tr::rich),
|
||||
st::urlAuthCheckboxAbout),
|
||||
st::boxRowPadding);
|
||||
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
if (!platform.isEmpty() || !browser.isEmpty()) {
|
||||
AddAuthInfoRow(
|
||||
content,
|
||||
platform,
|
||||
browser,
|
||||
tr::lng_url_auth_device_label(tr::now),
|
||||
st::menuIconDevices);
|
||||
}
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
|
||||
if (!ip.isEmpty() || !region.isEmpty()) {
|
||||
AddAuthInfoRow(
|
||||
content,
|
||||
ip,
|
||||
region,
|
||||
tr::lng_url_auth_ip_label(tr::now),
|
||||
st::menuIconAddress);
|
||||
}
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddSkip(content);
|
||||
|
||||
Ui::AddDividerText(
|
||||
content,
|
||||
rpl::single(tr::lng_url_auth_login_attempt(tr::now)));
|
||||
Ui::AddSkip(content);
|
||||
|
||||
auto allowMessages = (Ui::SettingsButton*)(nullptr);
|
||||
if (botName) {
|
||||
allowMessages = content->add(
|
||||
object_ptr<Ui::SettingsButton>(
|
||||
content,
|
||||
tr::lng_url_auth_allow_messages_label()));
|
||||
allowMessages->toggleOn(rpl::single(false));
|
||||
Ui::AddSkip(content);
|
||||
Ui::AddDividerText(
|
||||
content,
|
||||
tr::lng_url_auth_allow_messages_about(
|
||||
lt_bot,
|
||||
std::move(botName)));
|
||||
Ui::AddSkip(content);
|
||||
}
|
||||
|
||||
box->addButton(tr::lng_url_auth_login_button(), [=] {
|
||||
callback({
|
||||
.auth = true,
|
||||
.allowWrite = (allowMessages && allowMessages->toggled()),
|
||||
});
|
||||
});
|
||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||
}
|
||||
|
||||
} // namespace UrlAuthBox
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
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 "ui/widgets/buttons.h"
|
||||
|
||||
namespace Ui {
|
||||
class GenericBox;
|
||||
class VerticalLayout;
|
||||
} // namespace Ui
|
||||
|
||||
namespace UrlAuthBox {
|
||||
|
||||
struct Result {
|
||||
bool auth : 1 = false;
|
||||
bool allowWrite : 1 = false;
|
||||
bool sharePhone : 1 = false;
|
||||
};
|
||||
|
||||
class SwitchableUserpicButton final : public Ui::RippleButton {
|
||||
public:
|
||||
SwitchableUserpicButton(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
int size);
|
||||
|
||||
void setExpanded(bool expanded);
|
||||
void setUserpic(not_null<Ui::RpWidget*>);
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
QImage prepareRippleMask() const override;
|
||||
QPoint prepareRippleStartPosition() const override;
|
||||
|
||||
const int _size;
|
||||
const int _userpicSize;
|
||||
const int _skip;
|
||||
bool _expanded = false;
|
||||
Ui::RpWidget *_userpic = nullptr;
|
||||
|
||||
};
|
||||
|
||||
void AddAuthInfoRow(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
const QString &topText,
|
||||
const QString &bottomText,
|
||||
const QString &leftText,
|
||||
const style::icon &icon);
|
||||
|
||||
void Show(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
const QString &url,
|
||||
const QString &domain,
|
||||
const QString &selfName,
|
||||
const QString &botName,
|
||||
Fn<void(Result)> callback);
|
||||
|
||||
void ShowDetails(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
const QString &url,
|
||||
const QString &domain,
|
||||
Fn<void(Result)> callback,
|
||||
object_ptr<Ui::RpWidget> userpicOwned,
|
||||
rpl::producer<QString> botName,
|
||||
const QString &browser,
|
||||
const QString &platform,
|
||||
const QString &ip,
|
||||
const QString ®ion);
|
||||
|
||||
} // namespace UrlAuthBox
|
||||
@@ -63,6 +63,9 @@ PRIVATE
|
||||
boxes/peers/toggle_topics_box.cpp
|
||||
boxes/peers/toggle_topics_box.h
|
||||
|
||||
boxes/url_auth_box_content.cpp
|
||||
boxes/url_auth_box_content.h
|
||||
|
||||
calls/group/ui/calls_group_recording_box.cpp
|
||||
calls/group/ui/calls_group_recording_box.h
|
||||
calls/group/ui/calls_group_scheduled_labels.cpp
|
||||
|
||||
Reference in New Issue
Block a user