2015-04-02 10:33:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2015-04-02 10:33:19 +00:00
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/sessions_box.h"
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2015-04-02 10:33:19 +00:00
|
|
|
#include "mainwidget.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2015-04-02 10:33:19 +00:00
|
|
|
#include "countries.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2016-10-27 21:19:38 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
SessionsBox::SessionsBox(QWidget*)
|
|
|
|
: _shortPollTimer(this) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void SessionsBox::prepare() {
|
2017-05-30 15:21:05 +00:00
|
|
|
setTitle(langFactory(lng_sessions_other_header));
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
addButton(langFactory(lng_close), [this] { closeBox(); });
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
setDimensions(st::boxWideWidth, st::sessionsHeight);
|
|
|
|
|
2018-06-03 19:52:23 +00:00
|
|
|
_inner = setInnerWidget(object_ptr<Inner>(this, &_list, &_current), st::sessionsScroll);
|
|
|
|
_inner->resize(width(), st::noContactsHeight);
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
connect(_inner, SIGNAL(oneTerminated()), this, SLOT(onOneTerminated()));
|
|
|
|
connect(_inner, SIGNAL(allTerminated()), this, SLOT(onAllTerminated()));
|
|
|
|
connect(_inner, SIGNAL(terminateAll()), this, SLOT(onTerminateAll()));
|
2016-12-13 07:59:57 +00:00
|
|
|
connect(App::wnd(), SIGNAL(checkNewAuthorization()), this, SLOT(onCheckNewAuthorization()));
|
2016-12-13 17:07:56 +00:00
|
|
|
connect(_shortPollTimer, SIGNAL(timeout()), this, SLOT(onShortPollAuthorizations()));
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
setLoading(true);
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
MTP::send(MTPaccount_GetAuthorizations(), rpcDone(&SessionsBox::gotAuthorizations));
|
|
|
|
}
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
void SessionsBox::setLoading(bool loading) {
|
|
|
|
if (_loading != loading) {
|
|
|
|
_loading = loading;
|
2016-12-13 17:07:56 +00:00
|
|
|
setInnerVisible(!_loading);
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
void SessionsBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
|
|
|
_inner->resize(width(), _inner->height());
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SessionsBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2016-11-19 14:47:28 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
if (_loading) {
|
2016-11-18 13:34:58 +00:00
|
|
|
p.setFont(st::noContactsFont);
|
|
|
|
p.setPen(st::noContactsColor);
|
2015-04-02 10:33:19 +00:00
|
|
|
p.drawText(QRect(0, 0, width(), st::noContactsHeight), lang(lng_contacts_loading), style::al_center);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SessionsBox::gotAuthorizations(const MTPaccount_Authorizations &result) {
|
|
|
|
_shortPollRequest = 0;
|
2016-11-18 13:34:58 +00:00
|
|
|
setLoading(false);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2018-06-04 20:25:21 +00:00
|
|
|
const auto availCurrent = st::boxWideWidth - st::sessionPadding.left() - st::sessionTerminateSkip;
|
|
|
|
const auto availOther = availCurrent - st::sessionTerminate.iconPosition.x();
|
|
|
|
const auto availInfo = availCurrent - st::sessionTerminate.width;
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
_list.clear();
|
2016-11-18 13:34:58 +00:00
|
|
|
if (result.type() != mtpc_account_authorizations) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-10 19:46:28 +00:00
|
|
|
auto &v = result.c_account_authorizations().vauthorizations.v;
|
2016-11-18 13:34:58 +00:00
|
|
|
_list.reserve(v.size());
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
const CountriesByISO2 &countries(countriesByISO2());
|
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
for_const (auto &auth, v) {
|
|
|
|
if (auth.type() != mtpc_authorization) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto &d = auth.c_authorization();
|
2016-10-20 16:32:15 +00:00
|
|
|
Data data;
|
2015-04-02 10:33:19 +00:00
|
|
|
data.hash = d.vhash.v;
|
|
|
|
|
2015-04-06 22:15:29 +00:00
|
|
|
QString appName, appVer = qs(d.vapp_version), systemVer = qs(d.vsystem_version), deviceModel = qs(d.vdevice_model);
|
|
|
|
if (d.vapi_id.v == 2040 || d.vapi_id.v == 17349) {
|
2015-06-27 13:02:00 +00:00
|
|
|
appName = (d.vapi_id.v == 2040) ? qstr("Telegram Desktop") : qstr("Telegram Desktop (GitHub)");
|
|
|
|
// if (systemVer == qstr("windows")) {
|
2015-04-06 22:15:29 +00:00
|
|
|
// deviceModel = qsl("Windows");
|
2015-06-27 13:02:00 +00:00
|
|
|
// } else if (systemVer == qstr("os x")) {
|
2015-04-06 22:15:29 +00:00
|
|
|
// deviceModel = qsl("OS X");
|
2015-06-27 13:02:00 +00:00
|
|
|
// } else if (systemVer == qstr("linux")) {
|
2015-04-06 22:15:29 +00:00
|
|
|
// deviceModel = qsl("Linux");
|
|
|
|
// }
|
|
|
|
if (appVer == QString::number(appVer.toInt())) {
|
|
|
|
int32 ver = appVer.toInt();
|
|
|
|
appVer = QString("%1.%2").arg(ver / 1000000).arg((ver % 1000000) / 1000) + ((ver % 1000) ? ('.' + QString::number(ver % 1000)) : QString());
|
2017-06-05 13:33:45 +00:00
|
|
|
//} else {
|
|
|
|
// appVer = QString();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-04 20:01:34 +00:00
|
|
|
appName = qs(d.vapp_name);// +qsl(" for ") + qs(d.vplatform);
|
2015-04-06 22:15:29 +00:00
|
|
|
if (appVer.indexOf('(') >= 0) appVer = appVer.mid(appVer.indexOf('('));
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
data.name = appName;
|
2015-04-06 22:15:29 +00:00
|
|
|
if (!appVer.isEmpty()) data.name += ' ' + appVer;
|
2015-10-03 10:09:09 +00:00
|
|
|
data.nameWidth = st::sessionNameFont->width(data.name);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2015-04-06 22:15:29 +00:00
|
|
|
QString country = qs(d.vcountry), platform = qs(d.vplatform);
|
|
|
|
//CountriesByISO2::const_iterator j = countries.constFind(country);
|
|
|
|
//if (j != countries.cend()) country = QString::fromUtf8(j.value()->name);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
const auto active = data.activeTime = d.vdate_active.v
|
|
|
|
? d.vdate_active.v
|
|
|
|
: d.vdate_created.v;
|
2015-04-06 22:15:29 +00:00
|
|
|
|
2015-06-27 13:02:00 +00:00
|
|
|
data.info = qs(d.vdevice_model) + qstr(", ") + (platform.isEmpty() ? QString() : platform + ' ') + qs(d.vsystem_version);
|
2015-04-06 22:15:29 +00:00
|
|
|
data.ip = qs(d.vip) + (country.isEmpty() ? QString() : QString::fromUtf8(" \xe2\x80\x93 ") + country);
|
2015-04-02 10:33:19 +00:00
|
|
|
if (!data.hash || (d.vflags.v & 1)) {
|
2015-10-12 21:02:10 +00:00
|
|
|
data.active = lang(lng_sessions_header);
|
2016-10-31 12:29:26 +00:00
|
|
|
data.activeWidth = st::sessionWhenFont->width(lang(lng_sessions_header));
|
2015-10-12 21:02:10 +00:00
|
|
|
int32 availForName = availCurrent - st::sessionPadding.right() - data.activeWidth;
|
|
|
|
if (data.nameWidth > availForName) {
|
|
|
|
data.name = st::sessionNameFont->elided(data.name, availForName);
|
2015-10-03 10:09:09 +00:00
|
|
|
data.nameWidth = st::sessionNameFont->width(data.name);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2015-10-03 10:09:09 +00:00
|
|
|
data.infoWidth = st::sessionInfoFont->width(data.info);
|
2015-04-02 10:33:19 +00:00
|
|
|
if (data.infoWidth > availCurrent) {
|
2015-10-03 10:09:09 +00:00
|
|
|
data.info = st::sessionInfoFont->elided(data.info, availCurrent);
|
|
|
|
data.infoWidth = st::sessionInfoFont->width(data.info);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2015-10-03 10:09:09 +00:00
|
|
|
data.ipWidth = st::sessionInfoFont->width(data.ip);
|
2015-04-06 22:15:29 +00:00
|
|
|
if (data.ipWidth > availCurrent) {
|
2015-10-03 10:09:09 +00:00
|
|
|
data.ip = st::sessionInfoFont->elided(data.ip, availCurrent);
|
|
|
|
data.ipWidth = st::sessionInfoFont->width(data.ip);
|
2015-04-06 22:15:29 +00:00
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
_current = data;
|
|
|
|
} else {
|
2018-02-03 19:52:35 +00:00
|
|
|
const auto now = QDateTime::currentDateTime();
|
|
|
|
const auto lastTime = ParseDateTime(active);
|
|
|
|
const auto nowDate = now.date();
|
|
|
|
const auto lastDate = lastTime.date();
|
2015-04-04 20:01:34 +00:00
|
|
|
QString dt;
|
|
|
|
if (lastDate == nowDate) {
|
|
|
|
data.active = lastTime.toString(cTimeFormat());
|
2018-02-03 19:52:35 +00:00
|
|
|
} else if (lastDate.year() == nowDate.year()
|
|
|
|
&& lastDate.weekNumber() == nowDate.weekNumber()) {
|
2015-04-04 20:01:34 +00:00
|
|
|
data.active = langDayOfWeek(lastDate);
|
|
|
|
} else {
|
|
|
|
data.active = lastDate.toString(qsl("d.MM.yy"));
|
|
|
|
}
|
2016-10-31 12:29:26 +00:00
|
|
|
data.activeWidth = st::sessionWhenFont->width(data.active);
|
2015-04-02 10:33:19 +00:00
|
|
|
int32 availForName = availOther - st::sessionPadding.right() - data.activeWidth;
|
|
|
|
if (data.nameWidth > availForName) {
|
2015-10-03 10:09:09 +00:00
|
|
|
data.name = st::sessionNameFont->elided(data.name, availForName);
|
|
|
|
data.nameWidth = st::sessionNameFont->width(data.name);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2015-10-03 10:09:09 +00:00
|
|
|
data.infoWidth = st::sessionInfoFont->width(data.info);
|
2018-06-04 20:25:21 +00:00
|
|
|
if (data.infoWidth > availInfo) {
|
|
|
|
data.info = st::sessionInfoFont->elided(data.info, availInfo);
|
2015-10-03 10:09:09 +00:00
|
|
|
data.infoWidth = st::sessionInfoFont->width(data.info);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2015-10-03 10:09:09 +00:00
|
|
|
data.ipWidth = st::sessionInfoFont->width(data.ip);
|
2015-04-06 22:15:29 +00:00
|
|
|
if (data.ipWidth > availOther) {
|
2015-10-03 10:09:09 +00:00
|
|
|
data.ip = st::sessionInfoFont->elided(data.ip, availOther);
|
|
|
|
data.ipWidth = st::sessionInfoFont->width(data.ip);
|
2015-04-06 22:15:29 +00:00
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
_list.push_back(data);
|
|
|
|
for (int32 i = _list.size(); i > 1;) {
|
|
|
|
--i;
|
2015-04-05 08:40:56 +00:00
|
|
|
if (_list.at(i).activeTime > _list.at(i - 1).activeTime) {
|
2015-04-02 10:33:19 +00:00
|
|
|
qSwap(_list[i], _list[i - 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
_inner->listUpdated();
|
2016-11-18 13:34:58 +00:00
|
|
|
|
|
|
|
update();
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
_shortPollTimer->start(SessionsShortPollTimeout);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SessionsBox::onOneTerminated() {
|
2016-11-18 13:34:58 +00:00
|
|
|
update();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SessionsBox::onShortPollAuthorizations() {
|
|
|
|
if (!_shortPollRequest) {
|
|
|
|
_shortPollRequest = MTP::send(MTPaccount_GetAuthorizations(), rpcDone(&SessionsBox::gotAuthorizations));
|
2016-11-18 13:34:58 +00:00
|
|
|
update();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 07:59:57 +00:00
|
|
|
void SessionsBox::onCheckNewAuthorization() {
|
2015-04-02 10:33:19 +00:00
|
|
|
onShortPollAuthorizations();
|
|
|
|
// _shortPollTimer.start(1000);
|
|
|
|
}
|
|
|
|
|
2015-10-12 21:02:10 +00:00
|
|
|
void SessionsBox::onAllTerminated() {
|
2015-04-02 10:33:19 +00:00
|
|
|
MTP::send(MTPaccount_GetAuthorizations(), rpcDone(&SessionsBox::gotAuthorizations));
|
|
|
|
if (_shortPollRequest) {
|
|
|
|
MTP::cancel(_shortPollRequest);
|
|
|
|
_shortPollRequest = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-12 21:02:10 +00:00
|
|
|
void SessionsBox::onTerminateAll() {
|
2016-11-18 13:34:58 +00:00
|
|
|
setLoading(true);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
SessionsBox::Inner::Inner(QWidget *parent, SessionsBox::List *list, SessionsBox::Data *current) : TWidget(parent)
|
2016-10-20 16:32:15 +00:00
|
|
|
, _list(list)
|
|
|
|
, _current(current)
|
2016-12-13 17:07:56 +00:00
|
|
|
, _terminateAll(this, lang(lng_sessions_terminate_all), st::sessionTerminateAllButton) {
|
2016-11-11 13:46:04 +00:00
|
|
|
connect(_terminateAll, SIGNAL(clicked()), this, SLOT(onTerminateAll()));
|
|
|
|
_terminateAll->hide();
|
2016-10-20 16:32:15 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SessionsBox::Inner::paintEvent(QPaintEvent *e) {
|
|
|
|
QRect r(e->rect());
|
|
|
|
Painter p(this);
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(r, st::boxBg);
|
2016-10-27 21:19:38 +00:00
|
|
|
int32 x = st::sessionPadding.left(), xact = st::sessionTerminateSkip + st::sessionTerminate.iconPosition.x();// st::sessionTerminateSkip + st::sessionTerminate.width + st::sessionTerminateSkip;
|
2016-10-20 16:32:15 +00:00
|
|
|
int32 w = width();
|
|
|
|
|
|
|
|
if (_current->active.isEmpty() && _list->isEmpty()) {
|
|
|
|
p.setFont(st::noContactsFont->f);
|
|
|
|
p.setPen(st::noContactsColor->p);
|
|
|
|
p.drawText(QRect(0, 0, width(), st::noContactsHeight), lang(lng_contacts_loading), style::al_center);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-04 20:25:21 +00:00
|
|
|
p.translate(0, st::sessionCurrentPadding.top());
|
2016-10-20 16:32:15 +00:00
|
|
|
if (r.y() <= st::sessionCurrentHeight) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setFont(st::sessionNameFont);
|
|
|
|
p.setPen(st::sessionNameFg);
|
2016-10-20 16:32:15 +00:00
|
|
|
p.drawTextLeft(x, st::sessionPadding.top(), w, _current->name, _current->nameWidth);
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setFont(st::sessionWhenFont);
|
|
|
|
p.setPen(st::sessionWhenFg);
|
2016-10-20 16:32:15 +00:00
|
|
|
p.drawTextRight(x, st::sessionPadding.top(), w, _current->active, _current->activeWidth);
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setFont(st::sessionInfoFont);
|
|
|
|
p.setPen(st::boxTextFg);
|
2016-10-20 16:32:15 +00:00
|
|
|
p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height, w, _current->info, _current->infoWidth);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::sessionInfoFg);
|
2016-10-20 16:32:15 +00:00
|
|
|
p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height + st::sessionInfoFont->height, w, _current->ip, _current->ipWidth);
|
|
|
|
}
|
|
|
|
p.translate(0, st::sessionCurrentHeight - st::sessionCurrentPadding.top());
|
|
|
|
if (_list->isEmpty()) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setFont(st::sessionInfoFont);
|
|
|
|
p.setPen(st::sessionInfoFg);
|
2016-10-20 16:32:15 +00:00
|
|
|
p.drawText(QRect(st::sessionPadding.left(), 0, width() - st::sessionPadding.left() - st::sessionPadding.right(), st::noContactsHeight), lang(lng_sessions_other_desc), style::al_topleft);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setFont(st::linkFont->f);
|
|
|
|
int32 count = _list->size();
|
|
|
|
int32 from = floorclamp(r.y() - st::sessionCurrentHeight, st::sessionHeight, 0, count);
|
|
|
|
int32 to = ceilclamp(r.y() + r.height() - st::sessionCurrentHeight, st::sessionHeight, 0, count);
|
|
|
|
p.translate(0, from * st::sessionHeight);
|
|
|
|
for (int32 i = from; i < to; ++i) {
|
|
|
|
const SessionsBox::Data &auth(_list->at(i));
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setFont(st::sessionNameFont);
|
|
|
|
p.setPen(st::sessionNameFg);
|
2016-10-20 16:32:15 +00:00
|
|
|
p.drawTextLeft(x, st::sessionPadding.top(), w, auth.name, auth.nameWidth);
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setFont(st::sessionWhenFont);
|
|
|
|
p.setPen(st::sessionWhenFg);
|
2016-10-20 16:32:15 +00:00
|
|
|
p.drawTextRight(xact, st::sessionPadding.top(), w, auth.active, auth.activeWidth);
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setFont(st::sessionInfoFont);
|
|
|
|
p.setPen(st::boxTextFg);
|
2016-10-20 16:32:15 +00:00
|
|
|
p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height, w, auth.info, auth.infoWidth);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::sessionInfoFg);
|
2016-10-20 16:32:15 +00:00
|
|
|
p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height + st::sessionInfoFont->height, w, auth.ip, auth.ipWidth);
|
|
|
|
|
|
|
|
p.translate(0, st::sessionHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SessionsBox::Inner::onTerminate() {
|
2016-12-20 13:03:51 +00:00
|
|
|
for (auto i = _terminateButtons.begin(), e = _terminateButtons.end(); i != e; ++i) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (i.value()->isOver()) {
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_terminateBox) _terminateBox->deleteLater();
|
2018-06-04 15:35:11 +00:00
|
|
|
_terminateBox = Ui::show(Box<ConfirmBox>(lang(lng_settings_reset_one_sure), lang(lng_settings_reset_button), st::attentionBoxButton, crl::guard(this, [this, terminating = i.key()] {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_terminateBox) {
|
|
|
|
_terminateBox->closeBox();
|
|
|
|
_terminateBox = nullptr;
|
|
|
|
}
|
|
|
|
MTP::send(MTPaccount_ResetAuthorization(MTP_long(terminating)), rpcDone(&Inner::terminateDone, terminating), rpcFail(&Inner::terminateFail, terminating));
|
2016-12-20 13:03:51 +00:00
|
|
|
auto i = _terminateButtons.find(terminating);
|
2016-12-13 17:07:56 +00:00
|
|
|
if (i != _terminateButtons.cend()) {
|
|
|
|
i.value()->clearState();
|
|
|
|
i.value()->hide();
|
|
|
|
}
|
2017-09-15 17:34:41 +00:00
|
|
|
})), LayerOption::KeepOther);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SessionsBox::Inner::onTerminateAll() {
|
|
|
|
if (_terminateBox) _terminateBox->deleteLater();
|
2018-06-04 15:35:11 +00:00
|
|
|
_terminateBox = Ui::show(Box<ConfirmBox>(lang(lng_settings_reset_sure), lang(lng_settings_reset_button), st::attentionBoxButton, crl::guard(this, [this] {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_terminateBox) {
|
|
|
|
_terminateBox->closeBox();
|
|
|
|
_terminateBox = nullptr;
|
|
|
|
}
|
2017-01-30 15:27:13 +00:00
|
|
|
MTP::send(MTPauth_ResetAuthorizations(), rpcDone(&Inner::terminateAllDone), rpcFail(&Inner::terminateAllFail));
|
2016-12-13 17:07:56 +00:00
|
|
|
emit terminateAll();
|
2017-09-15 17:34:41 +00:00
|
|
|
})), LayerOption::KeepOther);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SessionsBox::Inner::terminateDone(uint64 hash, const MTPBool &result) {
|
|
|
|
for (int32 i = 0, l = _list->size(); i < l; ++i) {
|
|
|
|
if (_list->at(i).hash == hash) {
|
|
|
|
_list->removeAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
listUpdated();
|
|
|
|
emit oneTerminated();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SessionsBox::Inner::terminateFail(uint64 hash, const RPCError &error) {
|
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
|
|
|
|
|
|
|
TerminateButtons::iterator i = _terminateButtons.find(hash);
|
|
|
|
if (i != _terminateButtons.end()) {
|
|
|
|
i.value()->show();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SessionsBox::Inner::terminateAllDone(const MTPBool &result) {
|
|
|
|
emit allTerminated();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SessionsBox::Inner::terminateAllFail(const RPCError &error) {
|
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
|
|
|
emit allTerminated();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SessionsBox::Inner::resizeEvent(QResizeEvent *e) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_terminateAll->moveToLeft(st::sessionPadding.left(), st::sessionCurrentPadding.top() + st::sessionHeight + st::sessionCurrentPadding.bottom());
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SessionsBox::Inner::listUpdated() {
|
|
|
|
if (_list->isEmpty()) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_terminateAll->hide();
|
2016-10-20 16:32:15 +00:00
|
|
|
} else {
|
2016-11-11 13:46:04 +00:00
|
|
|
_terminateAll->show();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
for (TerminateButtons::iterator i = _terminateButtons.begin(), e = _terminateButtons.end(); i != e; ++i) {
|
|
|
|
i.value()->move(0, -1);
|
|
|
|
}
|
|
|
|
for (int32 i = 0, l = _list->size(); i < l; ++i) {
|
|
|
|
TerminateButtons::iterator j = _terminateButtons.find(_list->at(i).hash);
|
|
|
|
if (j == _terminateButtons.cend()) {
|
2016-10-27 21:19:38 +00:00
|
|
|
j = _terminateButtons.insert(_list->at(i).hash, new Ui::IconButton(this, st::sessionTerminate));
|
2016-10-20 16:32:15 +00:00
|
|
|
connect(j.value(), SIGNAL(clicked()), this, SLOT(onTerminate()));
|
|
|
|
}
|
|
|
|
j.value()->moveToRight(st::sessionTerminateSkip, st::sessionCurrentHeight + i * st::sessionHeight + st::sessionTerminateTop, width());
|
|
|
|
j.value()->show();
|
|
|
|
}
|
|
|
|
for (TerminateButtons::iterator i = _terminateButtons.begin(); i != _terminateButtons.cend();) {
|
|
|
|
if (i.value()->y() >= 0) {
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
delete i.value();
|
|
|
|
i = _terminateButtons.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resize(width(), _list->isEmpty() ? (st::sessionCurrentHeight + st::noContactsHeight) : (st::sessionCurrentHeight + _list->size() * st::sessionHeight));
|
|
|
|
update();
|
|
|
|
}
|