2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
2016-09-15 19:15:49 +00:00
|
|
|
#include "boxes/confirmbox.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-08 14:43:10 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2016-09-15 19:15:49 +00:00
|
|
|
#include "lang.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "mainwidget.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "apiwrap.h"
|
2015-09-23 17:43:08 +00:00
|
|
|
#include "application.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "core/click_handler_types.h"
|
2016-09-15 19:15:49 +00:00
|
|
|
#include "localstorage.h"
|
2015-09-23 17:43:08 +00:00
|
|
|
|
2014-12-05 13:44:27 +00:00
|
|
|
TextParseOptions _confirmBoxTextOptions = {
|
|
|
|
TextParseLinks | TextParseMultiline | TextParseRichText, // flags
|
|
|
|
0, // maxw
|
|
|
|
0, // maxh
|
|
|
|
Qt::LayoutDirectionAuto, // dir
|
|
|
|
};
|
|
|
|
|
2016-06-22 17:11:35 +00:00
|
|
|
ConfirmBox::ConfirmBox(const QString &text, const QString &doneText, const style::RoundButton &doneStyle, const QString &cancelText, const style::RoundButton &cancelStyle) : AbstractBox(st::boxWidth)
|
2016-03-04 22:04:15 +00:00
|
|
|
, _informative(false)
|
|
|
|
, _text(100)
|
|
|
|
, _confirm(this, doneText.isEmpty() ? lang(lng_box_ok) : doneText, doneStyle)
|
|
|
|
, _cancel(this, cancelText.isEmpty() ? lang(lng_cancel) : cancelText, cancelStyle) {
|
2014-12-05 13:44:27 +00:00
|
|
|
init(text);
|
|
|
|
}
|
|
|
|
|
2016-06-22 17:11:35 +00:00
|
|
|
ConfirmBox::ConfirmBox(const QString &text, const QString &doneText, const style::RoundButton &doneStyle, bool informative) : AbstractBox(st::boxWidth)
|
2016-03-04 22:04:15 +00:00
|
|
|
, _informative(true)
|
|
|
|
, _text(100)
|
|
|
|
, _confirm(this, doneText.isEmpty() ? lang(lng_box_ok) : doneText, doneStyle)
|
|
|
|
, _cancel(this, QString(), st::cancelBoxButton) {
|
2014-12-05 13:44:27 +00:00
|
|
|
init(text);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2014-12-05 13:44:27 +00:00
|
|
|
void ConfirmBox::init(const QString &text) {
|
2015-10-03 10:09:09 +00:00
|
|
|
_text.setText(st::boxTextFont, text, _informative ? _confirmBoxTextOptions : _textPlainOptions);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
connect(_confirm, SIGNAL(clicked()), this, SLOT(onConfirmPressed()));
|
|
|
|
connect(_cancel, SIGNAL(clicked()), this, SLOT(onCancel()));
|
2015-10-03 10:09:09 +00:00
|
|
|
if (_informative) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_cancel->hide();
|
2015-10-03 10:09:09 +00:00
|
|
|
connect(this, SIGNAL(confirmed()), this, SLOT(onCancel()));
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
2016-08-12 15:22:11 +00:00
|
|
|
onTextUpdated();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
prepare();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 15:22:11 +00:00
|
|
|
void ConfirmBox::onConfirmPressed() {
|
|
|
|
if (_confirmedCallback) {
|
|
|
|
_confirmedCallback();
|
|
|
|
}
|
|
|
|
emit confirmed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::onTextUpdated() {
|
|
|
|
textstyleSet(&st::boxTextStyle);
|
|
|
|
_textWidth = st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.right();
|
|
|
|
_textHeight = qMin(_text.countHeight(_textWidth), 16 * int(st::boxTextStyle.lineHeight));
|
2016-10-28 09:20:24 +00:00
|
|
|
setMaxHeight(st::boxPadding.top() + _textHeight + st::boxPadding.bottom() + st::boxButtonPadding.top() + _confirm->height() + st::boxButtonPadding.bottom());
|
2016-08-12 15:22:11 +00:00
|
|
|
textstyleRestore();
|
|
|
|
|
|
|
|
setMouseTracking(_text.hasLinks());
|
|
|
|
}
|
|
|
|
|
2015-08-12 18:01:32 +00:00
|
|
|
void ConfirmBox::onCancel() {
|
|
|
|
emit cancelPressed();
|
|
|
|
onClose();
|
|
|
|
}
|
|
|
|
|
2014-12-05 13:44:27 +00:00
|
|
|
void ConfirmBox::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
_lastMousePos = e->globalPos();
|
|
|
|
updateHover();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::mousePressEvent(QMouseEvent *e) {
|
|
|
|
_lastMousePos = e->globalPos();
|
|
|
|
updateHover();
|
2016-03-29 17:17:00 +00:00
|
|
|
ClickHandler::pressed();
|
2016-08-16 16:53:10 +00:00
|
|
|
return LayerWidget::mousePressEvent(e);
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
_lastMousePos = e->globalPos();
|
|
|
|
updateHover();
|
2016-03-29 17:17:00 +00:00
|
|
|
if (ClickHandlerPtr activated = ClickHandler::unpressed()) {
|
2015-12-07 18:09:05 +00:00
|
|
|
Ui::hideLayer();
|
2016-03-29 17:17:00 +00:00
|
|
|
App::activateClickHandler(activated, e->button());
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::leaveEvent(QEvent *e) {
|
2016-03-29 17:17:00 +00:00
|
|
|
ClickHandler::clearActive(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
|
|
|
|
setCursor(active ? style::cur_pointer : style::cur_default);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) {
|
|
|
|
update();
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::updateLink() {
|
|
|
|
_lastMousePos = QCursor::pos();
|
|
|
|
updateHover();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::updateHover() {
|
|
|
|
QPoint m(mapFromGlobal(_lastMousePos));
|
2016-03-29 17:17:00 +00:00
|
|
|
|
2015-10-03 10:09:09 +00:00
|
|
|
textstyleSet(&st::boxTextStyle);
|
2016-04-13 18:29:32 +00:00
|
|
|
auto state = _text.getStateLeft(m.x() - st::boxPadding.left(), m.y() - st::boxPadding.top(), _textWidth, width());
|
2015-10-03 10:09:09 +00:00
|
|
|
textstyleRestore();
|
2016-03-29 17:17:00 +00:00
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
ClickHandler::setActive(state.link, this);
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
void ConfirmBox::closePressed() {
|
|
|
|
emit cancelled();
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void ConfirmBox::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
2016-08-12 15:22:11 +00:00
|
|
|
onConfirmPressed();
|
2015-04-02 10:33:19 +00:00
|
|
|
} else {
|
|
|
|
AbstractBox::keyPressEvent(e);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBox::paintEvent(QPaintEvent *e) {
|
2016-11-19 14:47:28 +00:00
|
|
|
AbstractBox::paintEvent(e);
|
|
|
|
|
|
|
|
Painter p(this);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
// draw box title / text
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFg);
|
2015-10-03 10:09:09 +00:00
|
|
|
textstyleSet(&st::boxTextStyle);
|
2015-10-14 11:51:37 +00:00
|
|
|
_text.drawLeftElided(p, st::boxPadding.left(), st::boxPadding.top(), _textWidth, width(), 16, style::al_left);
|
2015-10-03 10:09:09 +00:00
|
|
|
textstyleRestore();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
void ConfirmBox::resizeEvent(QResizeEvent *e) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_confirm->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _confirm->height());
|
|
|
|
_cancel->moveToRight(st::boxButtonPadding.right() + _confirm->width() + st::boxButtonPadding.left(), _confirm->y());
|
2016-08-17 15:14:08 +00:00
|
|
|
AbstractBox::resizeEvent(e);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-09-10 11:20:28 +00:00
|
|
|
|
2016-03-30 16:42:01 +00:00
|
|
|
SharePhoneConfirmBox::SharePhoneConfirmBox(PeerData *recipient)
|
|
|
|
: ConfirmBox(lang(lng_bot_share_phone), lang(lng_bot_share_phone_confirm))
|
|
|
|
, _recipient(recipient) {
|
|
|
|
connect(this, SIGNAL(confirmed()), this, SLOT(onConfirm()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SharePhoneConfirmBox::onConfirm() {
|
|
|
|
emit confirmed(_recipient);
|
|
|
|
}
|
|
|
|
|
2016-03-04 22:04:15 +00:00
|
|
|
ConfirmLinkBox::ConfirmLinkBox(const QString &url) : ConfirmBox(lang(lng_open_this_link) + qsl("\n\n") + url, lang(lng_open_link))
|
|
|
|
, _url(url) {
|
2015-09-10 11:20:28 +00:00
|
|
|
connect(this, SIGNAL(confirmed()), this, SLOT(onOpenLink()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmLinkBox::onOpenLink() {
|
2016-03-06 17:06:05 +00:00
|
|
|
Ui::hideLayer();
|
2016-04-06 13:19:25 +00:00
|
|
|
UrlClickHandler::doOpen(_url);
|
2015-09-10 11:20:28 +00:00
|
|
|
}
|
2015-09-23 17:43:08 +00:00
|
|
|
|
2016-09-15 19:15:49 +00:00
|
|
|
ConfirmBotGameBox::ConfirmBotGameBox(UserData *bot, const QString &url) : ConfirmBox(lng_allow_bot_pass(lt_bot_name, bot->name), lang(lng_allow_bot))
|
|
|
|
, _bot(bot)
|
|
|
|
, _url(url) {
|
|
|
|
connect(this, SIGNAL(confirmed()), this, SLOT(onOpenLink()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmBotGameBox::onOpenLink() {
|
|
|
|
Ui::hideLayer();
|
|
|
|
Local::makeBotTrusted(_bot);
|
|
|
|
UrlClickHandler::doOpen(_url);
|
|
|
|
}
|
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
MaxInviteBox::MaxInviteBox(const QString &link) : AbstractBox(st::boxWidth)
|
|
|
|
, _close(this, lang(lng_box_ok), st::defaultBoxButton)
|
2016-02-18 16:36:33 +00:00
|
|
|
, _text(st::boxTextFont, lng_participant_invite_sorry(lt_count, Global::ChatSizeMax()), _confirmBoxTextOptions, st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.right())
|
2015-12-08 12:33:37 +00:00
|
|
|
, _link(link)
|
|
|
|
, _linkOver(false)
|
|
|
|
, a_goodOpacity(0, 0)
|
|
|
|
, _a_good(animation(this, &MaxInviteBox::step_good)) {
|
2015-09-23 17:43:08 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
|
2015-10-11 08:37:24 +00:00
|
|
|
_textWidth = st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.right();
|
2015-10-03 10:09:09 +00:00
|
|
|
_textHeight = qMin(_text.countHeight(_textWidth), 16 * int(st::boxTextStyle.lineHeight));
|
2016-10-28 09:20:24 +00:00
|
|
|
setMaxHeight(st::boxPadding.top() + _textHeight + st::boxTextFont->height + st::boxTextFont->height * 2 + st::newGroupLinkPadding.bottom() + st::boxButtonPadding.top() + _close->height() + st::boxButtonPadding.bottom());
|
2015-09-23 17:43:08 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
connect(_close, SIGNAL(clicked()), this, SLOT(onClose()));
|
2015-09-23 17:43:08 +00:00
|
|
|
|
|
|
|
prepare();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaxInviteBox::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
updateSelected(e->globalPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaxInviteBox::mousePressEvent(QMouseEvent *e) {
|
|
|
|
mouseMoveEvent(e);
|
|
|
|
if (_linkOver) {
|
2016-01-30 18:24:18 +00:00
|
|
|
Application::clipboard()->setText(_link);
|
2015-09-23 17:43:08 +00:00
|
|
|
_goodTextLink = lang(lng_create_channel_link_copied);
|
|
|
|
a_goodOpacity = anim::fvalue(1, 0);
|
2015-12-08 12:33:37 +00:00
|
|
|
_a_good.start();
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaxInviteBox::leaveEvent(QEvent *e) {
|
|
|
|
updateSelected(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaxInviteBox::updateSelected(const QPoint &cursorGlobalPosition) {
|
|
|
|
QPoint p(mapFromGlobal(cursorGlobalPosition));
|
|
|
|
|
|
|
|
bool linkOver = _invitationLink.contains(p);
|
|
|
|
if (linkOver != _linkOver) {
|
|
|
|
_linkOver = linkOver;
|
|
|
|
update();
|
|
|
|
setCursor(_linkOver ? style::cur_pointer : style::cur_default);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
void MaxInviteBox::step_good(float64 ms, bool timer) {
|
2015-09-23 17:43:08 +00:00
|
|
|
float dt = ms / st::newGroupLinkFadeDuration;
|
|
|
|
if (dt >= 1) {
|
2015-12-08 12:33:37 +00:00
|
|
|
_a_good.stop();
|
2015-09-23 17:43:08 +00:00
|
|
|
a_goodOpacity.finish();
|
|
|
|
} else {
|
|
|
|
a_goodOpacity.update(dt, anim::linear);
|
|
|
|
}
|
2015-12-08 12:33:37 +00:00
|
|
|
if (timer) update();
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MaxInviteBox::paintEvent(QPaintEvent *e) {
|
2016-11-19 14:47:28 +00:00
|
|
|
AbstractBox::paintEvent(e);
|
|
|
|
|
2015-09-23 17:43:08 +00:00
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
// draw box title / text
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFg);
|
2015-10-14 11:51:37 +00:00
|
|
|
_text.drawLeftElided(p, st::boxPadding.left(), st::boxPadding.top(), _textWidth, width(), 16, style::al_left);
|
2015-09-23 17:43:08 +00:00
|
|
|
|
|
|
|
QTextOption option(style::al_left);
|
|
|
|
option.setWrapMode(QTextOption::WrapAnywhere);
|
2015-10-12 21:02:10 +00:00
|
|
|
p.setFont(_linkOver ? st::defaultInputField.font->underline() : st::defaultInputField.font);
|
2016-11-11 13:46:04 +00:00
|
|
|
p.setPen(st::defaultLinkButton.color);
|
2015-09-23 17:43:08 +00:00
|
|
|
p.drawText(_invitationLink, _link, option);
|
|
|
|
if (!_goodTextLink.isEmpty() && a_goodOpacity.current() > 0) {
|
|
|
|
p.setOpacity(a_goodOpacity.current());
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFgGood);
|
2016-09-29 11:37:16 +00:00
|
|
|
p.setFont(st::boxTextFont);
|
2016-10-28 09:20:24 +00:00
|
|
|
p.drawTextLeft(st::boxPadding.left(), height() - st::boxButtonPadding.bottom() - _close->height() + st::defaultBoxButton.textTop + st::defaultBoxButton.font->ascent - st::boxTextFont->ascent, width(), _goodTextLink);
|
2015-09-23 17:43:08 +00:00
|
|
|
p.setOpacity(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaxInviteBox::resizeEvent(QResizeEvent *e) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_close->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _close->height());
|
2015-10-11 08:37:24 +00:00
|
|
|
_invitationLink = myrtlrect(st::boxPadding.left(), st::boxPadding.top() + _textHeight + st::boxTextFont->height, width() - st::boxPadding.left() - st::boxPadding.right(), 2 * st::boxTextFont->height);
|
2016-08-17 15:14:08 +00:00
|
|
|
AbstractBox::resizeEvent(e);
|
2015-09-23 17:43:08 +00:00
|
|
|
}
|
2016-03-04 22:04:15 +00:00
|
|
|
|
2016-11-19 14:47:28 +00:00
|
|
|
ConvertToSupergroupBox::ConvertToSupergroupBox(ChatData *chat) : AbstractBox(st::boxWideWidth, lang(lng_profile_convert_title))
|
2016-03-04 22:04:15 +00:00
|
|
|
, _chat(chat)
|
|
|
|
, _text(100)
|
|
|
|
, _note(100)
|
|
|
|
, _convert(this, lang(lng_profile_convert_confirm), st::defaultBoxButton)
|
|
|
|
, _cancel(this, lang(lng_cancel), st::cancelBoxButton) {
|
|
|
|
QStringList text;
|
|
|
|
text.push_back(lang(lng_profile_convert_feature1));
|
|
|
|
text.push_back(lang(lng_profile_convert_feature2));
|
|
|
|
text.push_back(lang(lng_profile_convert_feature3));
|
|
|
|
text.push_back(lang(lng_profile_convert_feature4));
|
|
|
|
|
|
|
|
textstyleSet(&st::boxTextStyle);
|
|
|
|
_text.setText(st::boxTextFont, text.join('\n'), _confirmBoxTextOptions);
|
|
|
|
_note.setText(st::boxTextFont, lng_profile_convert_warning(lt_bold_start, textcmdStartSemibold(), lt_bold_end, textcmdStopSemibold()), _confirmBoxTextOptions);
|
|
|
|
_textWidth = st::boxWideWidth - st::boxPadding.left() - st::boxButtonPadding.right();
|
|
|
|
_textHeight = _text.countHeight(_textWidth);
|
2016-11-08 14:43:10 +00:00
|
|
|
setMaxHeight(titleHeight() + _textHeight + st::boxPadding.bottom() + _note.countHeight(_textWidth) + st::boxButtonPadding.top() + _convert->height() + st::boxButtonPadding.bottom());
|
2016-03-04 22:04:15 +00:00
|
|
|
textstyleRestore();
|
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
connect(_convert, SIGNAL(clicked()), this, SLOT(onConvert()));
|
|
|
|
connect(_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
|
2016-03-04 22:04:15 +00:00
|
|
|
|
|
|
|
prepare();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertToSupergroupBox::onConvert() {
|
|
|
|
MTP::send(MTPmessages_MigrateChat(_chat->inputChat), rpcDone(&ConvertToSupergroupBox::convertDone), rpcFail(&ConvertToSupergroupBox::convertFail));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertToSupergroupBox::convertDone(const MTPUpdates &updates) {
|
|
|
|
Ui::hideLayer();
|
|
|
|
App::main()->sentUpdatesReceived(updates);
|
|
|
|
const QVector<MTPChat> *v = 0;
|
|
|
|
switch (updates.type()) {
|
|
|
|
case mtpc_updates: v = &updates.c_updates().vchats.c_vector().v; break;
|
|
|
|
case mtpc_updatesCombined: v = &updates.c_updatesCombined().vchats.c_vector().v; break;
|
|
|
|
default: LOG(("API Error: unexpected update cons %1 (ConvertToSupergroupBox::convertDone)").arg(updates.type())); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PeerData *peer = 0;
|
|
|
|
if (v && !v->isEmpty()) {
|
|
|
|
for (int32 i = 0, l = v->size(); i < l; ++i) {
|
|
|
|
if (v->at(i).type() == mtpc_channel) {
|
|
|
|
peer = App::channel(v->at(i).c_channel().vid.v);
|
|
|
|
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
|
|
|
|
QTimer::singleShot(ReloadChannelMembersTimeout, App::api(), SLOT(delayedRequestParticipantsCount()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!peer) {
|
|
|
|
LOG(("API Error: channel not found in updates (ProfileInner::migrateDone)"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConvertToSupergroupBox::convertFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2016-03-04 22:04:15 +00:00
|
|
|
Ui::hideLayer();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertToSupergroupBox::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
|
|
|
onConvert();
|
|
|
|
} else {
|
|
|
|
AbstractBox::keyPressEvent(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertToSupergroupBox::paintEvent(QPaintEvent *e) {
|
2016-11-19 14:47:28 +00:00
|
|
|
AbstractBox::paintEvent(e);
|
2016-03-04 22:04:15 +00:00
|
|
|
|
2016-11-19 14:47:28 +00:00
|
|
|
Painter p(this);
|
2016-03-04 22:04:15 +00:00
|
|
|
|
|
|
|
// draw box title / text
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::boxTextFg);
|
2016-03-04 22:04:15 +00:00
|
|
|
textstyleSet(&st::boxTextStyle);
|
2016-11-08 14:43:10 +00:00
|
|
|
_text.drawLeft(p, st::boxPadding.left(), titleHeight(), _textWidth, width());
|
|
|
|
_note.drawLeft(p, st::boxPadding.left(), titleHeight() + _textHeight + st::boxPadding.bottom(), _textWidth, width());
|
2016-03-04 22:04:15 +00:00
|
|
|
textstyleRestore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertToSupergroupBox::resizeEvent(QResizeEvent *e) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_convert->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _convert->height());
|
|
|
|
_cancel->moveToRight(st::boxButtonPadding.right() + _convert->width() + st::boxButtonPadding.left(), _convert->y());
|
2016-08-17 15:14:08 +00:00
|
|
|
AbstractBox::resizeEvent(e);
|
2016-03-04 22:04:15 +00:00
|
|
|
}
|
2016-03-10 10:15:21 +00:00
|
|
|
|
|
|
|
PinMessageBox::PinMessageBox(ChannelData *channel, MsgId msgId) : AbstractBox(st::boxWidth)
|
|
|
|
, _channel(channel)
|
|
|
|
, _msgId(msgId)
|
2016-11-16 10:44:06 +00:00
|
|
|
, _text(this, lang(lng_pinned_pin_sure), Ui::FlatLabel::InitType::Simple, st::boxLabel)
|
2016-06-10 11:18:55 +00:00
|
|
|
, _notify(this, lang(lng_pinned_notify), true, st::defaultBoxCheckbox)
|
2016-03-10 10:15:21 +00:00
|
|
|
, _pin(this, lang(lng_pinned_pin), st::defaultBoxButton)
|
2016-05-31 19:27:11 +00:00
|
|
|
, _cancel(this, lang(lng_cancel), st::cancelBoxButton) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_text->resizeToWidth(st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.right());
|
|
|
|
setMaxHeight(st::boxPadding.top() + _text->height() + st::boxMediumSkip + _notify->height() + st::boxPadding.bottom() + st::boxButtonPadding.top() + _pin->height() + st::boxButtonPadding.bottom());
|
2016-03-10 10:15:21 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
connect(_pin, SIGNAL(clicked()), this, SLOT(onPin()));
|
|
|
|
connect(_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
|
2016-03-10 10:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PinMessageBox::resizeEvent(QResizeEvent *e) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_text->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
|
|
|
|
_notify->moveToLeft(st::boxPadding.left(), _text->y() + _text->height() + st::boxMediumSkip);
|
|
|
|
_pin->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _pin->height());
|
|
|
|
_cancel->moveToRight(st::boxButtonPadding.right() + _pin->width() + st::boxButtonPadding.left(), _pin->y());
|
2016-08-17 15:14:08 +00:00
|
|
|
AbstractBox::resizeEvent(e);
|
2016-03-10 10:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PinMessageBox::onPin() {
|
|
|
|
if (_requestId) return;
|
|
|
|
|
2016-03-19 16:55:15 +00:00
|
|
|
MTPchannels_UpdatePinnedMessage::Flags flags = 0;
|
2016-10-28 09:20:24 +00:00
|
|
|
if (!_notify->checked()) {
|
2016-03-19 16:55:15 +00:00
|
|
|
flags |= MTPchannels_UpdatePinnedMessage::Flag::f_silent;
|
|
|
|
}
|
|
|
|
_requestId = MTP::send(MTPchannels_UpdatePinnedMessage(MTP_flags(flags), _channel->inputChannel, MTP_int(_msgId)), rpcDone(&PinMessageBox::pinDone), rpcFail(&PinMessageBox::pinFail));
|
2016-03-10 10:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PinMessageBox::pinDone(const MTPUpdates &updates) {
|
|
|
|
if (App::main()) {
|
|
|
|
App::main()->sentUpdatesReceived(updates);
|
|
|
|
}
|
|
|
|
Ui::hideLayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PinMessageBox::pinFail(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2016-03-10 10:15:21 +00:00
|
|
|
Ui::hideLayer();
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-10 15:42:01 +00:00
|
|
|
|
|
|
|
RichDeleteMessageBox::RichDeleteMessageBox(ChannelData *channel, UserData *from, MsgId msgId) : AbstractBox(st::boxWidth)
|
|
|
|
, _channel(channel)
|
|
|
|
, _from(from)
|
|
|
|
, _msgId(msgId)
|
2016-11-16 10:44:06 +00:00
|
|
|
, _text(this, lang(lng_selected_delete_sure_this), Ui::FlatLabel::InitType::Simple, st::boxLabel)
|
2016-06-10 11:18:55 +00:00
|
|
|
, _banUser(this, lang(lng_ban_user), false, st::defaultBoxCheckbox)
|
|
|
|
, _reportSpam(this, lang(lng_report_spam), false, st::defaultBoxCheckbox)
|
|
|
|
, _deleteAll(this, lang(lng_delete_all_from), false, st::defaultBoxCheckbox)
|
2016-03-10 15:42:01 +00:00
|
|
|
, _delete(this, lang(lng_box_delete), st::defaultBoxButton)
|
2016-03-13 15:45:00 +00:00
|
|
|
, _cancel(this, lang(lng_cancel), st::cancelBoxButton) {
|
|
|
|
t_assert(_channel != nullptr);
|
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
_text->resizeToWidth(st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.right());
|
|
|
|
setMaxHeight(st::boxPadding.top() + _text->height() + st::boxMediumSkip + _banUser->height() + st::boxLittleSkip + _reportSpam->height() + st::boxLittleSkip + _deleteAll->height() + st::boxPadding.bottom() + st::boxButtonPadding.top() + _delete->height() + st::boxButtonPadding.bottom());
|
2016-03-10 15:42:01 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
connect(_delete, SIGNAL(clicked()), this, SLOT(onDelete()));
|
|
|
|
connect(_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RichDeleteMessageBox::resizeEvent(QResizeEvent *e) {
|
2016-10-28 09:20:24 +00:00
|
|
|
_text->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
|
|
|
|
_banUser->moveToLeft(st::boxPadding.left(), _text->y() + _text->height() + st::boxMediumSkip);
|
|
|
|
_reportSpam->moveToLeft(st::boxPadding.left(), _banUser->y() + _banUser->height() + st::boxLittleSkip);
|
|
|
|
_deleteAll->moveToLeft(st::boxPadding.left(), _reportSpam->y() + _reportSpam->height() + st::boxLittleSkip);
|
|
|
|
_delete->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _delete->height());
|
|
|
|
_cancel->moveToRight(st::boxButtonPadding.right() + _delete->width() + st::boxButtonPadding.left(), _delete->y());
|
2016-08-17 15:14:08 +00:00
|
|
|
AbstractBox::resizeEvent(e);
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RichDeleteMessageBox::onDelete() {
|
2016-10-28 09:20:24 +00:00
|
|
|
if (_banUser->checked()) {
|
2016-03-13 15:45:00 +00:00
|
|
|
MTP::send(MTPchannels_KickFromChannel(_channel->inputChannel, _from->inputUser, MTP_boolTrue()), App::main()->rpcDone(&MainWidget::sentUpdatesReceived));
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
2016-10-28 09:20:24 +00:00
|
|
|
if (_reportSpam->checked()) {
|
2016-03-13 15:45:00 +00:00
|
|
|
MTP::send(MTPchannels_ReportSpam(_channel->inputChannel, _from->inputUser, MTP_vector<MTPint>(1, MTP_int(_msgId))));
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
2016-10-28 09:20:24 +00:00
|
|
|
if (_deleteAll->checked()) {
|
2016-03-13 15:45:00 +00:00
|
|
|
App::main()->deleteAllFromUser(_channel, _from);
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
2016-03-14 16:59:18 +00:00
|
|
|
if (HistoryItem *item = App::histItemById(_channel ? peerToChannel(_channel->id) : 0, _msgId)) {
|
2016-03-13 15:45:00 +00:00
|
|
|
bool wasLast = (item->history()->lastMsg == item);
|
|
|
|
item->destroy();
|
2016-06-02 13:02:55 +00:00
|
|
|
|
2016-03-13 15:45:00 +00:00
|
|
|
if (_msgId > 0) {
|
|
|
|
App::main()->deleteMessages(_channel, QVector<MTPint>(1, MTP_int(_msgId)));
|
|
|
|
} else if (wasLast) {
|
|
|
|
App::main()->checkPeerHistory(_channel);
|
2016-03-11 11:13:28 +00:00
|
|
|
}
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
2016-03-13 15:45:00 +00:00
|
|
|
Ui::hideLayer();
|
2016-03-10 15:42:01 +00:00
|
|
|
}
|
|
|
|
|
2016-06-20 15:40:36 +00:00
|
|
|
KickMemberBox::KickMemberBox(PeerData *chat, UserData *member)
|
|
|
|
: ConfirmBox(lng_profile_sure_kick(lt_user, member->firstName), lang(lng_box_remove))
|
|
|
|
, _chat(chat)
|
|
|
|
, _member(member) {
|
|
|
|
connect(this, SIGNAL(confirmed()), this, SLOT(onConfirm()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void KickMemberBox::onConfirm() {
|
|
|
|
Ui::hideLayer();
|
|
|
|
if (auto chat = _chat->asChat()) {
|
|
|
|
App::main()->kickParticipant(chat, _member);
|
|
|
|
} else if (auto channel = _chat->asChannel()) {
|
|
|
|
App::api()->kickParticipant(channel, _member);
|
|
|
|
}
|
|
|
|
}
|
2016-07-08 16:59:46 +00:00
|
|
|
|
|
|
|
ConfirmInviteBox::ConfirmInviteBox(const QString &title, const MTPChatPhoto &photo, int count, const QVector<UserData*> &participants) : AbstractBox()
|
|
|
|
, _title(this, st::confirmInviteTitle)
|
|
|
|
, _status(this, st::confirmInviteStatus)
|
|
|
|
, _photo(chatDefPhoto(0))
|
|
|
|
, _participants(participants)
|
|
|
|
, _join(this, lang(lng_group_invite_join), st::defaultBoxButton)
|
|
|
|
, _cancel(this, lang(lng_cancel), st::cancelBoxButton) {
|
|
|
|
if (_participants.size() > 4) {
|
|
|
|
_participants.resize(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
_title->setText(title);
|
|
|
|
QString status;
|
|
|
|
if (_participants.isEmpty() || _participants.size() >= count) {
|
|
|
|
status = lng_chat_status_members(lt_count, count);
|
|
|
|
} else {
|
|
|
|
status = lng_group_invite_members(lt_count, count);
|
|
|
|
}
|
|
|
|
_status->setText(status);
|
|
|
|
if (photo.type() == mtpc_chatPhoto) {
|
|
|
|
auto &d = photo.c_chatPhoto();
|
|
|
|
auto location = App::imageLocation(160, 160, d.vphoto_small);
|
|
|
|
if (!location.isNull()) {
|
|
|
|
_photo = ImagePtr(location);
|
|
|
|
if (!_photo->loaded()) {
|
2016-09-26 13:57:08 +00:00
|
|
|
subscribe(FileDownload::ImageLoaded(), [this] { update(); });
|
2016-07-08 16:59:46 +00:00
|
|
|
_photo->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int h = st::confirmInviteStatusTop + _status->height() + st::boxPadding.bottom() + st::boxButtonPadding.top() + _join->height() + st::boxButtonPadding.bottom();
|
|
|
|
if (!_participants.isEmpty()) {
|
|
|
|
int skip = (width() - 4 * st::confirmInviteUserPhotoSize) / 5;
|
|
|
|
int padding = skip / 2;
|
|
|
|
_userWidth = (st::confirmInviteUserPhotoSize + 2 * padding);
|
|
|
|
int sumWidth = _participants.size() * _userWidth;
|
|
|
|
int left = (width() - sumWidth) / 2;
|
|
|
|
for_const (auto user, _participants) {
|
2016-11-16 10:44:06 +00:00
|
|
|
auto name = new Ui::FlatLabel(this, st::confirmInviteUserName);
|
2016-07-08 16:59:46 +00:00
|
|
|
name->resizeToWidth(st::confirmInviteUserPhotoSize + padding);
|
|
|
|
name->setText(user->firstName.isEmpty() ? App::peerName(user) : user->firstName);
|
|
|
|
name->moveToLeft(left + (padding / 2), st::confirmInviteUserNameTop);
|
|
|
|
left += _userWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
h += st::confirmInviteUserHeight;
|
|
|
|
}
|
|
|
|
setMaxHeight(h);
|
|
|
|
|
|
|
|
connect(_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
|
|
|
|
connect(_join, SIGNAL(clicked()), App::main(), SLOT(onInviteImport()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmInviteBox::resizeEvent(QResizeEvent *e) {
|
|
|
|
_title->move((width() - _title->width()) / 2, st::confirmInviteTitleTop);
|
|
|
|
_status->move((width() - _status->width()) / 2, st::confirmInviteStatusTop);
|
|
|
|
_join->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _join->height());
|
|
|
|
_cancel->moveToRight(st::boxButtonPadding.right() + _join->width() + st::boxButtonPadding.left(), _join->y());
|
2016-08-17 15:14:08 +00:00
|
|
|
AbstractBox::resizeEvent(e);
|
2016-07-08 16:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfirmInviteBox::paintEvent(QPaintEvent *e) {
|
2016-11-19 14:47:28 +00:00
|
|
|
AbstractBox::paintEvent(e);
|
|
|
|
|
2016-07-08 16:59:46 +00:00
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
p.drawPixmap((width() - st::confirmInvitePhotoSize) / 2, st::confirmInvitePhotoTop, _photo->pixCircled(st::confirmInvitePhotoSize, st::confirmInvitePhotoSize));
|
|
|
|
|
|
|
|
int sumWidth = _participants.size() * _userWidth;
|
|
|
|
int left = (width() - sumWidth) / 2;
|
|
|
|
for_const (auto user, _participants) {
|
|
|
|
user->paintUserpicLeft(p, st::confirmInviteUserPhotoSize, left + (_userWidth - st::confirmInviteUserPhotoSize) / 2, st::confirmInviteUserPhotoTop, width());
|
|
|
|
left += _userWidth;
|
|
|
|
}
|
|
|
|
}
|