2015-05-19 18:46:45 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
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 16:16:42 +03: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.
|
|
|
|
|
2015-05-19 18:46:45 +03:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2016-02-08 13:56:18 +03:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2015-05-19 18:46:45 +03:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "lang.h"
|
|
|
|
|
|
|
|
#include "stickersetbox.h"
|
|
|
|
#include "mainwidget.h"
|
2016-04-13 00:31:28 +03:00
|
|
|
#include "mainwindow.h"
|
2016-09-09 18:52:46 +03:00
|
|
|
#include "stickers/stickers.h"
|
2015-05-19 18:46:45 +03:00
|
|
|
#include "boxes/confirmbox.h"
|
2016-04-13 00:31:28 +03:00
|
|
|
#include "apiwrap.h"
|
2015-05-19 18:46:45 +03:00
|
|
|
#include "localstorage.h"
|
2016-06-28 21:05:38 +03:00
|
|
|
#include "dialogs/dialogs_layout.h"
|
2016-07-18 18:39:10 +03:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
|
2016-07-21 16:57:31 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr int kArchivedLimitFirstRequest = 10;
|
|
|
|
constexpr int kArchivedLimitPerPage = 30;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2016-02-17 19:37:21 +03:00
|
|
|
StickerSetInner::StickerSetInner(const MTPInputStickerSet &set) : TWidget()
|
2016-06-27 19:25:21 +03:00
|
|
|
, _input(set) {
|
2015-10-11 10:37:24 +02:00
|
|
|
connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update()));
|
2015-05-19 18:46:45 +03:00
|
|
|
switch (set.type()) {
|
|
|
|
case mtpc_inputStickerSetID: _setId = set.c_inputStickerSetID().vid.v; _setAccess = set.c_inputStickerSetID().vaccess_hash.v; break;
|
|
|
|
case mtpc_inputStickerSetShortName: _setShortName = qs(set.c_inputStickerSetShortName().vshort_name); break;
|
|
|
|
}
|
|
|
|
MTP::send(MTPmessages_GetStickerSet(_input), rpcDone(&StickerSetInner::gotSet), rpcFail(&StickerSetInner::failedSet));
|
|
|
|
App::main()->updateStickers();
|
2016-02-17 19:37:21 +03:00
|
|
|
|
|
|
|
_previewTimer.setSingleShot(true);
|
|
|
|
connect(&_previewTimer, SIGNAL(timeout()), this, SLOT(onPreview()));
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickerSetInner::gotSet(const MTPmessages_StickerSet &set) {
|
|
|
|
_pack.clear();
|
2016-01-09 20:51:42 +08:00
|
|
|
_emoji.clear();
|
2015-05-19 18:46:45 +03:00
|
|
|
if (set.type() == mtpc_messages_stickerSet) {
|
2016-06-28 21:05:38 +03:00
|
|
|
auto &d(set.c_messages_stickerSet());
|
|
|
|
auto &v(d.vdocuments.c_vector().v);
|
2015-05-19 18:46:45 +03:00
|
|
|
_pack.reserve(v.size());
|
2016-06-28 21:05:38 +03:00
|
|
|
for (int i = 0, l = v.size(); i < l; ++i) {
|
|
|
|
auto doc = App::feedDocument(v.at(i));
|
2015-07-01 00:07:05 +03:00
|
|
|
if (!doc || !doc->sticker()) continue;
|
2016-01-09 19:24:16 +08:00
|
|
|
|
2015-05-19 18:46:45 +03:00
|
|
|
_pack.push_back(doc);
|
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
auto &packs(d.vpacks.c_vector().v);
|
|
|
|
for (int i = 0, l = packs.size(); i < l; ++i) {
|
2016-01-09 20:51:42 +08:00
|
|
|
if (packs.at(i).type() != mtpc_stickerPack) continue;
|
2016-06-28 21:05:38 +03:00
|
|
|
auto &pack(packs.at(i).c_stickerPack());
|
|
|
|
if (auto e = emojiGetNoColor(emojiFromText(qs(pack.vemoticon)))) {
|
|
|
|
auto &stickers(pack.vdocuments.c_vector().v);
|
2016-01-09 20:51:42 +08:00
|
|
|
StickerPack p;
|
|
|
|
p.reserve(stickers.size());
|
|
|
|
for (int32 j = 0, c = stickers.size(); j < c; ++j) {
|
|
|
|
DocumentData *doc = App::document(stickers.at(j).v);
|
|
|
|
if (!doc || !doc->sticker()) continue;
|
|
|
|
|
|
|
|
p.push_back(doc);
|
|
|
|
}
|
|
|
|
_emoji.insert(e, p);
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 18:46:45 +03:00
|
|
|
if (d.vset.type() == mtpc_stickerSet) {
|
2016-06-28 21:05:38 +03:00
|
|
|
auto &s(d.vset.c_stickerSet());
|
2015-12-02 20:17:53 +03:00
|
|
|
_setTitle = stickerSetTitle(s);
|
2015-10-11 10:37:24 +02:00
|
|
|
_title = st::boxTitleFont->elided(_setTitle, width() - st::boxTitlePosition.x() - st::boxTitleHeight);
|
2015-05-19 18:46:45 +03:00
|
|
|
_setShortName = qs(s.vshort_name);
|
|
|
|
_setId = s.vid.v;
|
|
|
|
_setAccess = s.vaccess_hash.v;
|
2015-06-28 15:37:10 +03:00
|
|
|
_setCount = s.vcount.v;
|
|
|
|
_setHash = s.vhash.v;
|
|
|
|
_setFlags = s.vflags.v;
|
2016-06-28 21:05:38 +03:00
|
|
|
auto &sets = Global::RefStickerSets();
|
|
|
|
auto it = sets.find(_setId);
|
|
|
|
if (it != sets.cend()) {
|
2016-07-15 18:58:52 +03:00
|
|
|
auto clientFlags = it->flags & (MTPDstickerSet_ClientFlag::f_featured | MTPDstickerSet_ClientFlag::f_not_loaded | MTPDstickerSet_ClientFlag::f_unread | MTPDstickerSet_ClientFlag::f_special);
|
2016-06-28 21:05:38 +03:00
|
|
|
_setFlags |= clientFlags;
|
|
|
|
it->flags = _setFlags;
|
|
|
|
it->stickers = _pack;
|
|
|
|
it->emoji = _emoji;
|
|
|
|
}
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-21 17:35:08 +02:00
|
|
|
if (_pack.isEmpty()) {
|
2015-12-07 21:09:05 +03:00
|
|
|
Ui::showLayer(new InformBox(lang(lng_stickers_not_found)));
|
2015-05-19 18:46:45 +03:00
|
|
|
} else {
|
|
|
|
int32 rows = _pack.size() / StickerPanPerRow + ((_pack.size() % StickerPanPerRow) ? 1 : 0);
|
2015-10-11 10:37:24 +02:00
|
|
|
resize(st::stickersPadding.left() + StickerPanPerRow * st::stickersSize.width(), st::stickersPadding.top() + rows * st::stickersSize.height() + st::stickersPadding.bottom());
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
|
|
|
_loaded = true;
|
|
|
|
|
|
|
|
emit updateButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StickerSetInner::failedSet(const RPCError &error) {
|
2016-04-08 14:44:35 +04:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2015-05-19 18:46:45 +03:00
|
|
|
|
|
|
|
_loaded = true;
|
|
|
|
|
2015-12-07 21:09:05 +03:00
|
|
|
Ui::showLayer(new InformBox(lang(lng_stickers_not_found)));
|
2015-05-19 18:46:45 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-18 18:39:10 +03:00
|
|
|
void StickerSetInner::installDone(const MTPmessages_StickerSetInstallResult &result) {
|
2016-06-27 19:25:21 +03:00
|
|
|
auto &sets = Global::RefStickerSets();
|
2015-05-21 13:44:26 +03:00
|
|
|
|
2016-07-21 16:57:31 +03:00
|
|
|
bool wasArchived = (_setFlags & MTPDstickerSet::Flag::f_archived);
|
|
|
|
if (wasArchived) {
|
|
|
|
auto index = Global::RefArchivedStickerSetsOrder().indexOf(_setId);
|
|
|
|
if (index >= 0) {
|
|
|
|
Global::RefArchivedStickerSetsOrder().removeAt(index);
|
|
|
|
}
|
|
|
|
}
|
2016-07-18 18:39:10 +03:00
|
|
|
_setFlags &= ~MTPDstickerSet::Flag::f_archived;
|
2016-06-27 19:25:21 +03:00
|
|
|
_setFlags |= MTPDstickerSet::Flag::f_installed;
|
2016-03-19 19:55:15 +03:00
|
|
|
auto it = sets.find(_setId);
|
2016-01-09 20:51:42 +08:00
|
|
|
if (it == sets.cend()) {
|
2016-03-19 19:55:15 +03:00
|
|
|
it = sets.insert(_setId, Stickers::Set(_setId, _setAccess, _setTitle, _setShortName, _setCount, _setHash, _setFlags));
|
2016-06-27 19:25:21 +03:00
|
|
|
} else {
|
2016-06-28 21:05:38 +03:00
|
|
|
it->flags = _setFlags;
|
2016-01-09 20:51:42 +08:00
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
it->stickers = _pack;
|
|
|
|
it->emoji = _emoji;
|
2015-06-28 15:37:10 +03:00
|
|
|
|
2016-06-27 19:25:21 +03:00
|
|
|
auto &order = Global::RefStickerSetsOrder();
|
2016-06-28 21:05:38 +03:00
|
|
|
int insertAtIndex = 0, currentIndex = order.indexOf(_setId);
|
2015-06-28 15:37:10 +03:00
|
|
|
if (currentIndex != insertAtIndex) {
|
|
|
|
if (currentIndex > 0) {
|
|
|
|
order.removeAt(currentIndex);
|
|
|
|
}
|
|
|
|
order.insert(insertAtIndex, _setId);
|
2015-05-21 13:44:26 +03:00
|
|
|
}
|
|
|
|
|
2016-03-19 19:55:15 +03:00
|
|
|
auto custom = sets.find(Stickers::CustomSetId);
|
2015-05-19 18:58:22 +03:00
|
|
|
if (custom != sets.cend()) {
|
2016-06-28 21:05:38 +03:00
|
|
|
for_const (auto sticker, _pack) {
|
|
|
|
int removeIndex = custom->stickers.indexOf(sticker);
|
2015-12-03 22:55:44 +03:00
|
|
|
if (removeIndex >= 0) custom->stickers.removeAt(removeIndex);
|
2015-05-19 18:58:22 +03:00
|
|
|
}
|
|
|
|
if (custom->stickers.isEmpty()) {
|
|
|
|
sets.erase(custom);
|
|
|
|
}
|
|
|
|
}
|
2016-07-18 18:39:10 +03:00
|
|
|
|
|
|
|
if (result.type() == mtpc_messages_stickerSetInstallResultArchive) {
|
|
|
|
Stickers::applyArchivedResult(result.c_messages_stickerSetInstallResultArchive());
|
2016-09-09 18:52:46 +03:00
|
|
|
} else {
|
|
|
|
if (wasArchived) {
|
|
|
|
Local::writeArchivedStickers();
|
|
|
|
}
|
|
|
|
Local::writeInstalledStickers();
|
|
|
|
emit App::main()->stickersUpdated();
|
2016-07-18 18:39:10 +03:00
|
|
|
}
|
2015-05-19 18:46:45 +03:00
|
|
|
emit installed(_setId);
|
|
|
|
}
|
|
|
|
|
2016-07-14 14:59:55 +03:00
|
|
|
bool StickerSetInner::installFail(const RPCError &error) {
|
2016-04-08 14:44:35 +04:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2015-05-19 18:46:45 +03:00
|
|
|
|
2016-07-18 18:39:10 +03:00
|
|
|
Ui::showLayer(new InformBox(lang(lng_stickers_not_found)));
|
2015-05-19 18:46:45 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-17 19:37:21 +03:00
|
|
|
void StickerSetInner::mousePressEvent(QMouseEvent *e) {
|
|
|
|
int32 index = stickerFromGlobalPos(e->globalPos());
|
|
|
|
if (index >= 0 && index < _pack.size()) {
|
|
|
|
_previewTimer.start(QApplication::startDragTime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickerSetInner::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
if (_previewShown >= 0) {
|
|
|
|
int32 index = stickerFromGlobalPos(e->globalPos());
|
|
|
|
if (index >= 0 && index < _pack.size() && index != _previewShown) {
|
|
|
|
_previewShown = index;
|
2016-04-10 22:18:26 +04:00
|
|
|
Ui::showMediaPreview(_pack.at(_previewShown));
|
2016-02-17 19:37:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickerSetInner::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
_previewTimer.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickerSetInner::onPreview() {
|
|
|
|
int32 index = stickerFromGlobalPos(QCursor::pos());
|
|
|
|
if (index >= 0 && index < _pack.size()) {
|
|
|
|
_previewShown = index;
|
2016-04-10 22:18:26 +04:00
|
|
|
Ui::showMediaPreview(_pack.at(_previewShown));
|
2016-02-17 19:37:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 StickerSetInner::stickerFromGlobalPos(const QPoint &p) const {
|
|
|
|
QPoint l(mapFromGlobal(p));
|
|
|
|
if (rtl()) l.setX(width() - l.x());
|
|
|
|
int32 row = (l.y() >= st::stickersPadding.top()) ? qFloor((l.y() - st::stickersPadding.top()) / st::stickersSize.height()) : -1;
|
|
|
|
int32 col = (l.x() >= st::stickersPadding.left()) ? qFloor((l.x() - st::stickersPadding.left()) / st::stickersSize.width()) : -1;
|
|
|
|
if (row >= 0 && col >= 0 && col < StickerPanPerRow) {
|
|
|
|
int32 result = row * StickerPanPerRow + col;
|
|
|
|
return (result < _pack.size()) ? result : -1;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-05-19 18:46:45 +03:00
|
|
|
void StickerSetInner::paintEvent(QPaintEvent *e) {
|
|
|
|
QRect r(e->rect());
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
if (_pack.isEmpty()) return;
|
|
|
|
|
|
|
|
int32 rows = _pack.size() / StickerPanPerRow + ((_pack.size() % StickerPanPerRow) ? 1 : 0);
|
|
|
|
int32 from = qFloor(e->rect().top() / st::stickersSize.height()), to = qFloor(e->rect().bottom() / st::stickersSize.height()) + 1;
|
|
|
|
|
|
|
|
for (int32 i = from; i < to; ++i) {
|
|
|
|
for (int32 j = 0; j < StickerPanPerRow; ++j) {
|
|
|
|
int32 index = i * StickerPanPerRow + j;
|
|
|
|
if (index >= _pack.size()) break;
|
|
|
|
|
|
|
|
DocumentData *doc = _pack.at(index);
|
2015-10-11 10:37:24 +02:00
|
|
|
QPoint pos(st::stickersPadding.left() + j * st::stickersSize.width(), st::stickersPadding.top() + i * st::stickersSize.height());
|
2015-05-19 18:46:45 +03:00
|
|
|
|
|
|
|
bool goodThumb = !doc->thumb->isNull() && ((doc->thumb->width() >= 128) || (doc->thumb->height() >= 128));
|
|
|
|
if (goodThumb) {
|
|
|
|
doc->thumb->load();
|
|
|
|
} else {
|
2015-12-24 22:26:28 +03:00
|
|
|
if (doc->status == FileReady) {
|
|
|
|
doc->automaticLoad(0);
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
2016-03-16 14:54:37 +03:00
|
|
|
if (doc->sticker()->img->isNull() && doc->loaded(DocumentData::FilePathResolveChecked)) {
|
|
|
|
doc->sticker()->img = doc->data().isEmpty() ? ImagePtr(doc->filepath()) : ImagePtr(doc->data());
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-07 15:35:14 +03:00
|
|
|
float64 coef = qMin((st::stickersSize.width() - st::buttonRadius * 2) / float64(doc->dimensions.width()), (st::stickersSize.height() - st::buttonRadius * 2) / float64(doc->dimensions.height()));
|
2015-05-19 18:46:45 +03:00
|
|
|
if (coef > 1) coef = 1;
|
|
|
|
int32 w = qRound(coef * doc->dimensions.width()), h = qRound(coef * doc->dimensions.height());
|
|
|
|
if (w < 1) w = 1;
|
|
|
|
if (h < 1) h = 1;
|
|
|
|
QPoint ppos = pos + QPoint((st::stickersSize.width() - w) / 2, (st::stickersSize.height() - h) / 2);
|
|
|
|
if (goodThumb) {
|
|
|
|
p.drawPixmapLeft(ppos, width(), doc->thumb->pix(w, h));
|
2015-07-01 00:07:05 +03:00
|
|
|
} else if (!doc->sticker()->img->isNull()) {
|
|
|
|
p.drawPixmapLeft(ppos, width(), doc->sticker()->img->pix(w, h));
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickerSetInner::setScrollBottom(int32 bottom) {
|
|
|
|
if (bottom == _bottom) return;
|
|
|
|
|
|
|
|
_bottom = bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StickerSetInner::loaded() const {
|
|
|
|
return _loaded && !_pack.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 StickerSetInner::notInstalled() const {
|
2015-12-02 20:17:53 +03:00
|
|
|
if (!_loaded) return 0;
|
2016-03-19 19:55:15 +03:00
|
|
|
auto it = Global::StickerSets().constFind(_setId);
|
2016-07-18 18:39:10 +03:00
|
|
|
if (it == Global::StickerSets().cend() || !(it->flags & MTPDstickerSet::Flag::f_installed) || (it->flags & MTPDstickerSet::Flag::f_archived)) return _pack.size();
|
2015-12-02 20:17:53 +03:00
|
|
|
return 0;
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
|
|
|
|
2015-07-21 17:35:08 +02:00
|
|
|
bool StickerSetInner::official() const {
|
|
|
|
return _loaded && _setShortName.isEmpty();
|
|
|
|
}
|
|
|
|
|
2015-05-19 18:46:45 +03:00
|
|
|
QString StickerSetInner::title() const {
|
|
|
|
return _loaded ? (_pack.isEmpty() ? lang(lng_attach_failed) : _title) : lang(lng_contacts_loading);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString StickerSetInner::shortName() const {
|
|
|
|
return _setShortName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickerSetInner::install() {
|
|
|
|
if (_installRequest) return;
|
2016-07-14 14:59:55 +03:00
|
|
|
_installRequest = MTP::send(MTPmessages_InstallStickerSet(_input, MTP_bool(false)), rpcDone(&StickerSetInner::installDone), rpcFail(&StickerSetInner::installFail));
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
StickerSetInner::~StickerSetInner() {
|
|
|
|
}
|
|
|
|
|
2015-10-11 10:37:24 +02:00
|
|
|
StickerSetBox::StickerSetBox(const MTPInputStickerSet &set) : ScrollableBox(st::stickersScroll)
|
|
|
|
, _inner(set)
|
|
|
|
, _shadow(this)
|
|
|
|
, _add(this, lang(lng_stickers_add_pack), st::defaultBoxButton)
|
|
|
|
, _share(this, lang(lng_stickers_share_pack), st::defaultBoxButton)
|
2015-10-12 23:02:10 +02:00
|
|
|
, _cancel(this, lang(lng_cancel), st::cancelBoxButton)
|
|
|
|
, _done(this, lang(lng_about_done), st::defaultBoxButton) {
|
2015-05-19 18:46:45 +03:00
|
|
|
setMaxHeight(st::stickersMaxHeight);
|
|
|
|
connect(App::main(), SIGNAL(stickersUpdated()), this, SLOT(onStickersUpdated()));
|
|
|
|
|
2015-10-11 10:37:24 +02:00
|
|
|
init(&_inner, st::boxButtonPadding.bottom() + _cancel.height() + st::boxButtonPadding.top());
|
2015-05-19 18:46:45 +03:00
|
|
|
|
2015-10-11 10:37:24 +02:00
|
|
|
connect(&_add, SIGNAL(clicked()), this, SLOT(onAddStickers()));
|
|
|
|
connect(&_share, SIGNAL(clicked()), this, SLOT(onShareStickers()));
|
|
|
|
connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
|
2015-10-12 23:02:10 +02:00
|
|
|
connect(&_done, SIGNAL(clicked()), this, SLOT(onClose()));
|
2015-05-19 18:46:45 +03:00
|
|
|
|
|
|
|
connect(&_inner, SIGNAL(updateButtons()), this, SLOT(onUpdateButtons()));
|
2016-09-06 15:28:37 +03:00
|
|
|
connect(scrollArea(), SIGNAL(scrolled()), this, SLOT(onScroll()));
|
2015-05-19 18:46:45 +03:00
|
|
|
|
2016-06-28 21:05:38 +03:00
|
|
|
connect(&_inner, SIGNAL(installed(uint64)), this, SLOT(onInstalled(uint64)));
|
2015-05-19 18:46:45 +03:00
|
|
|
|
|
|
|
onStickersUpdated();
|
|
|
|
|
|
|
|
onScroll();
|
|
|
|
|
|
|
|
prepare();
|
|
|
|
}
|
|
|
|
|
2016-06-28 21:05:38 +03:00
|
|
|
void StickerSetBox::onInstalled(uint64 setId) {
|
|
|
|
emit installed(setId);
|
|
|
|
onClose();
|
|
|
|
}
|
|
|
|
|
2015-05-19 18:46:45 +03:00
|
|
|
void StickerSetBox::onStickersUpdated() {
|
|
|
|
showAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickerSetBox::onAddStickers() {
|
|
|
|
_inner.install();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickerSetBox::onShareStickers() {
|
|
|
|
QString url = qsl("https://telegram.me/addstickers/") + _inner.shortName();
|
|
|
|
QApplication::clipboard()->setText(url);
|
2015-12-07 21:09:05 +03:00
|
|
|
Ui::showLayer(new InformBox(lang(lng_stickers_copied)));
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickerSetBox::onUpdateButtons() {
|
2015-10-12 23:02:10 +02:00
|
|
|
if (!_cancel.isHidden() || !_done.isHidden()) {
|
2015-10-11 10:37:24 +02:00
|
|
|
showAll();
|
|
|
|
}
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickerSetBox::onScroll() {
|
2016-09-06 15:28:37 +03:00
|
|
|
_inner.setScrollBottom(scrollArea()->scrollTop() + scrollArea()->height());
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickerSetBox::showAll() {
|
|
|
|
ScrollableBox::showAll();
|
|
|
|
int32 cnt = _inner.notInstalled();
|
|
|
|
if (_inner.loaded()) {
|
2015-10-12 23:02:10 +02:00
|
|
|
_shadow.show();
|
2015-12-02 20:17:53 +03:00
|
|
|
if (_inner.notInstalled()) {
|
2015-10-11 10:37:24 +02:00
|
|
|
_add.show();
|
2015-10-12 23:02:10 +02:00
|
|
|
_cancel.show();
|
2015-10-11 10:37:24 +02:00
|
|
|
_share.hide();
|
2015-10-12 23:02:10 +02:00
|
|
|
_done.hide();
|
2015-12-02 20:17:53 +03:00
|
|
|
} else if (_inner.official()) {
|
|
|
|
_add.hide();
|
|
|
|
_share.hide();
|
|
|
|
_cancel.hide();
|
|
|
|
_done.show();
|
2015-05-19 18:46:45 +03:00
|
|
|
} else {
|
2015-10-11 10:37:24 +02:00
|
|
|
_share.show();
|
2015-10-12 23:02:10 +02:00
|
|
|
_cancel.show();
|
2015-10-11 10:37:24 +02:00
|
|
|
_add.hide();
|
2015-10-12 23:02:10 +02:00
|
|
|
_done.hide();
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-12 23:02:10 +02:00
|
|
|
_shadow.hide();
|
2015-10-11 10:37:24 +02:00
|
|
|
_add.hide();
|
|
|
|
_share.hide();
|
2015-10-12 23:02:10 +02:00
|
|
|
_cancel.show();
|
|
|
|
_done.hide();
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
2015-10-11 10:37:24 +02:00
|
|
|
resizeEvent(0);
|
2015-05-19 18:46:45 +03:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickerSetBox::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
if (paint(p)) return;
|
|
|
|
|
2015-10-11 10:37:24 +02:00
|
|
|
paintTitle(p, _inner.title());
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickerSetBox::resizeEvent(QResizeEvent *e) {
|
|
|
|
ScrollableBox::resizeEvent(e);
|
|
|
|
_inner.resize(width(), _inner.height());
|
2015-10-11 10:37:24 +02:00
|
|
|
_shadow.setGeometry(0, height() - st::boxButtonPadding.bottom() - _cancel.height() - st::boxButtonPadding.top() - st::lineWidth, width(), st::lineWidth);
|
|
|
|
_add.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _add.height());
|
|
|
|
_share.moveToRight(st::boxButtonPadding.right(), _add.y());
|
2015-10-12 23:02:10 +02:00
|
|
|
_done.moveToRight(st::boxButtonPadding.right(), _add.y());
|
2015-10-11 10:37:24 +02:00
|
|
|
if (_add.isHidden() && _share.isHidden()) {
|
|
|
|
_cancel.moveToRight(st::boxButtonPadding.right(), _add.y());
|
|
|
|
} else if (_add.isHidden()) {
|
|
|
|
_cancel.moveToRight(st::boxButtonPadding.right() + _share.width() + st::boxButtonPadding.left(), _add.y());
|
|
|
|
} else {
|
|
|
|
_cancel.moveToRight(st::boxButtonPadding.right() + _add.width() + st::boxButtonPadding.left(), _add.y());
|
|
|
|
}
|
2015-05-19 18:46:45 +03:00
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
|
2016-06-28 21:05:38 +03:00
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
StickersInner::StickersInner(StickersBox::Section section) : TWidget()
|
|
|
|
, _section(section)
|
2015-12-02 20:17:53 +03:00
|
|
|
, _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom())
|
2015-12-08 15:33:37 +03:00
|
|
|
, _a_shifting(animation(this, &StickersInner::step_shifting))
|
2015-12-06 18:50:02 +03:00
|
|
|
, _itemsTop(st::membersPadding.top())
|
2016-07-15 18:58:52 +03:00
|
|
|
, _clearWidth(st::normalFont->width(lang(lng_stickers_clear_recent)))
|
2015-12-02 20:17:53 +03:00
|
|
|
, _removeWidth(st::normalFont->width(lang(lng_stickers_remove)))
|
|
|
|
, _returnWidth(st::normalFont->width(lang(lng_stickers_return)))
|
2015-12-06 18:50:02 +03:00
|
|
|
, _restoreWidth(st::normalFont->width(lang(lng_stickers_restore)))
|
2016-06-28 21:05:38 +03:00
|
|
|
, _aboveShadow(st::boxShadow) {
|
2016-07-18 18:39:10 +03:00
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
StickersInner::StickersInner(const Stickers::Order &archivedIds) : TWidget()
|
|
|
|
, _section(StickersBox::Section::ArchivedPart)
|
|
|
|
, _archivedIds(archivedIds)
|
|
|
|
, _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom())
|
|
|
|
, _a_shifting(animation(this, &StickersInner::step_shifting))
|
|
|
|
, _itemsTop(st::membersPadding.top())
|
|
|
|
, _clearWidth(st::normalFont->width(lang(lng_stickers_clear_recent)))
|
|
|
|
, _removeWidth(st::normalFont->width(lang(lng_stickers_remove)))
|
|
|
|
, _returnWidth(st::normalFont->width(lang(lng_stickers_return)))
|
|
|
|
, _restoreWidth(st::normalFont->width(lang(lng_stickers_restore)))
|
|
|
|
, _aboveShadow(st::boxShadow) {
|
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::setup() {
|
2015-12-02 20:17:53 +03:00
|
|
|
connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update()));
|
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:57:31 +03:00
|
|
|
void StickersInner::paintButton(Painter &p, int y, bool selected, const QString &text, int badgeCounter) const {
|
|
|
|
if (selected) {
|
|
|
|
p.fillRect(0, y, width(), _buttonHeight, st::contactsBgOver);
|
2016-06-28 21:05:38 +03:00
|
|
|
}
|
|
|
|
p.setFont(st::stickersFeaturedFont);
|
|
|
|
p.setPen(st::stickersFeaturedPen);
|
2016-07-21 16:57:31 +03:00
|
|
|
p.drawTextLeft(st::stickersFeaturedPosition.x(), y + st::stickersFeaturedPosition.y(), width(), text);
|
2016-06-28 21:05:38 +03:00
|
|
|
|
2016-07-21 16:57:31 +03:00
|
|
|
if (badgeCounter) {
|
2016-06-28 21:05:38 +03:00
|
|
|
Dialogs::Layout::UnreadBadgeStyle unreadSt;
|
|
|
|
unreadSt.sizeId = Dialogs::Layout::UnreadBadgeInStickersBox;
|
|
|
|
unreadSt.size = st::stickersFeaturedBadgeSize;
|
|
|
|
int unreadRight = width() - (st::contactsPadding.right() + st::contactsCheckPosition.x());
|
|
|
|
if (rtl()) unreadRight = width() - unreadRight;
|
2016-07-21 16:57:31 +03:00
|
|
|
int unreadTop = y + (_buttonHeight - st::stickersFeaturedBadgeSize) / 2;
|
|
|
|
Dialogs::Layout::paintUnreadCount(p, QString::number(badgeCounter), unreadRight, unreadTop, unreadSt);
|
2016-06-28 21:05:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-02 20:17:53 +03:00
|
|
|
void StickersInner::paintEvent(QPaintEvent *e) {
|
|
|
|
QRect r(e->rect());
|
|
|
|
Painter p(this);
|
|
|
|
|
2015-12-08 15:33:37 +03:00
|
|
|
_a_shifting.step();
|
2015-12-05 15:37:08 +03:00
|
|
|
|
2015-12-02 20:17:53 +03:00
|
|
|
p.fillRect(r, st::white);
|
|
|
|
p.setClipRect(r);
|
2016-06-28 21:05:38 +03:00
|
|
|
|
2016-07-21 16:57:31 +03:00
|
|
|
int y = st::membersPadding.top();
|
|
|
|
if (_hasFeaturedButton) {
|
|
|
|
auto selected = (_selected == -2);
|
|
|
|
paintButton(p, y, selected, lang(lng_stickers_featured), Global::FeaturedStickerSetsUnreadCount());
|
|
|
|
y += _buttonHeight;
|
|
|
|
}
|
|
|
|
if (_hasArchivedButton) {
|
|
|
|
auto selected = (_selected == -1);
|
|
|
|
paintButton(p, y, selected, lang(lng_stickers_archived), 0);
|
|
|
|
y += _buttonHeight;
|
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
|
2015-12-02 20:17:53 +03:00
|
|
|
if (_rows.isEmpty()) {
|
2016-06-28 21:05:38 +03:00
|
|
|
p.setFont(st::noContactsFont);
|
|
|
|
p.setPen(st::noContactsColor);
|
2016-07-21 16:57:31 +03:00
|
|
|
p.drawText(QRect(0, y, width(), st::noContactsHeight), lang(lng_contacts_loading), style::al_center);
|
2015-12-02 20:17:53 +03:00
|
|
|
} else {
|
2015-12-06 18:50:02 +03:00
|
|
|
p.translate(0, _itemsTop);
|
|
|
|
|
|
|
|
int32 yFrom = r.y() - _itemsTop, yTo = r.y() + r.height() - _itemsTop;
|
2015-12-02 20:17:53 +03:00
|
|
|
int32 from = floorclamp(yFrom - _rowHeight, _rowHeight, 0, _rows.size());
|
|
|
|
int32 to = ceilclamp(yTo + _rowHeight, _rowHeight, 0, _rows.size());
|
|
|
|
p.translate(0, from * _rowHeight);
|
|
|
|
for (int32 i = from; i < to; ++i) {
|
|
|
|
if (i != _above) {
|
|
|
|
paintRow(p, i);
|
|
|
|
}
|
|
|
|
p.translate(0, _rowHeight);
|
|
|
|
}
|
|
|
|
if (from <= _above && _above < to) {
|
|
|
|
p.translate(0, (_above - to) * _rowHeight);
|
|
|
|
paintRow(p, _above);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::paintRow(Painter &p, int32 index) {
|
|
|
|
const StickerSetRow *s(_rows.at(index));
|
|
|
|
|
2015-12-05 15:37:08 +03:00
|
|
|
int32 xadd = 0, yadd = s->yadd.current();
|
2015-12-02 20:17:53 +03:00
|
|
|
if (xadd || yadd) p.translate(xadd, yadd);
|
|
|
|
|
2016-06-28 21:05:38 +03:00
|
|
|
if (_section == Section::Installed) {
|
|
|
|
bool removeSel = (index == _actionSel && (_actionDown < 0 || index == _actionDown));
|
|
|
|
bool removeDown = removeSel && (index == _actionDown);
|
2015-12-02 20:17:53 +03:00
|
|
|
|
2016-06-28 21:05:38 +03:00
|
|
|
p.setFont(removeSel ? st::linkOverFont : st::linkFont);
|
|
|
|
if (removeDown) {
|
|
|
|
p.setPen(st::btnDefLink.downColor);
|
|
|
|
} else {
|
|
|
|
p.setPen(st::btnDefLink.color);
|
|
|
|
}
|
2016-07-15 18:58:52 +03:00
|
|
|
int32 remWidth = s->recent ? _clearWidth : (s->disabled ? (s->official ? _restoreWidth : _returnWidth) : _removeWidth);
|
|
|
|
QString remText = lang(s->recent ? lng_stickers_clear_recent : (s->disabled ? (s->official ? lng_stickers_restore : lng_stickers_return) : lng_stickers_remove));
|
2016-06-28 21:05:38 +03:00
|
|
|
p.drawTextRight(st::contactsPadding.right() + st::contactsCheckPosition.x(), st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, width(), remText, remWidth);
|
|
|
|
|
|
|
|
if (index == _above) {
|
|
|
|
float64 current = _aboveShadowFadeOpacity.current();
|
|
|
|
if (_started >= 0) {
|
|
|
|
float64 o = aboveShadowOpacity();
|
|
|
|
if (o > current) {
|
|
|
|
_aboveShadowFadeOpacity = anim::fvalue(o, o);
|
|
|
|
current = o;
|
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
p.setOpacity(current);
|
|
|
|
QRect row(myrtlrect(_aboveShadow.getDimensions(st::boxShadowShift).left(), st::contactsPadding.top() / 2, width() - (st::contactsPadding.left() / 2) - _scrollbar - _aboveShadow.getDimensions(st::boxShadowShift).right(), _rowHeight - ((st::contactsPadding.top() + st::contactsPadding.bottom()) / 2)));
|
|
|
|
_aboveShadow.paint(p, row, st::boxShadowShift);
|
|
|
|
p.fillRect(row, st::white);
|
|
|
|
p.setOpacity(1);
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
2016-07-18 18:39:10 +03:00
|
|
|
} else if (s->installed && !s->disabled) {
|
|
|
|
int addw = st::stickersAddSize.width();
|
2016-06-28 21:05:38 +03:00
|
|
|
int checkx = width() - (st::contactsPadding.right() + st::contactsCheckPosition.x() + (addw + st::stickersFeaturedInstalled.width()) / 2);
|
|
|
|
int checky = st::contactsPadding.top() + (st::contactsPhotoSize - st::stickersFeaturedInstalled.height()) / 2;
|
|
|
|
st::stickersFeaturedInstalled.paint(p, QPoint(checkx, checky), width());
|
|
|
|
} else {
|
2016-07-18 18:39:10 +03:00
|
|
|
int addw = st::stickersAddSize.width();
|
2016-06-28 21:05:38 +03:00
|
|
|
int addx = width() - st::contactsPadding.right() - st::contactsCheckPosition.x() - addw;
|
2016-07-18 18:39:10 +03:00
|
|
|
int addy = st::contactsPadding.top() + (st::contactsPhotoSize - st::stickersAddSize.height()) / 2;
|
|
|
|
QRect add(myrtlrect(addx, addy, addw, st::stickersAddSize.height()));
|
2016-06-28 21:05:38 +03:00
|
|
|
|
2016-07-08 20:24:48 +03:00
|
|
|
auto textBg = (_actionSel == index) ? st::defaultActiveButton.textBgOver : st::defaultActiveButton.textBg;
|
|
|
|
App::roundRect(p, add, textBg, ImageRoundRadius::Small);
|
2016-07-18 18:39:10 +03:00
|
|
|
int iconx = addx + (st::stickersAddSize.width() - st::stickersAddIcon.width()) / 2;
|
|
|
|
int icony = addy + (st::stickersAddSize.height() - st::stickersAddIcon.height()) / 2;
|
|
|
|
icony += (_actionSel == index && _actionDown == index) ? (st::defaultActiveButton.downTextTop - st::defaultActiveButton.textTop) : 0;
|
|
|
|
st::stickersAddIcon.paint(p, QPoint(iconx, icony), width());
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
|
2016-07-18 18:39:10 +03:00
|
|
|
if (s->disabled && _section == Section::Installed) {
|
|
|
|
p.setOpacity(st::stickersRowDisabledOpacity);
|
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
if (s->sticker) {
|
|
|
|
s->sticker->thumb->load();
|
|
|
|
QPixmap pix(s->sticker->thumb->pix(s->pixw, s->pixh));
|
|
|
|
p.drawPixmapLeft(st::contactsPadding.left() + (st::contactsPhotoSize - s->pixw) / 2, st::contactsPadding.top() + (st::contactsPhotoSize - s->pixh) / 2, width(), pix);
|
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
|
|
|
|
int namex = st::contactsPadding.left() + st::contactsPhotoSize + st::contactsPadding.left();
|
|
|
|
int namey = st::contactsPadding.top() + st::contactsNameTop;
|
|
|
|
int statusx = namex;
|
|
|
|
int statusy = st::contactsPadding.top() + st::contactsStatusTop;
|
|
|
|
|
|
|
|
if (s->unread) {
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::stickersFeaturedUnreadBg);
|
|
|
|
|
|
|
|
p.setRenderHint(QPainter::HighQualityAntialiasing, true);
|
|
|
|
p.drawEllipse(rtlrect(namex, namey + st::stickersFeaturedUnreadTop, st::stickersFeaturedUnreadSize, st::stickersFeaturedUnreadSize, width()));
|
|
|
|
p.setRenderHint(QPainter::HighQualityAntialiasing, false);
|
|
|
|
namex += st::stickersFeaturedUnreadSize + st::stickersFeaturedUnreadSkip;
|
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
p.setFont(st::contactsNameFont);
|
|
|
|
p.setPen(st::black);
|
2016-06-28 21:05:38 +03:00
|
|
|
p.drawTextLeft(namex, namey, width(), s->title);
|
2015-12-02 20:17:53 +03:00
|
|
|
|
|
|
|
p.setFont(st::contactsStatusFont);
|
|
|
|
p.setPen(st::contactsStatusFg);
|
2016-06-28 21:05:38 +03:00
|
|
|
p.drawTextLeft(statusx, statusy, width(), lng_stickers_count(lt_count, s->count));
|
2015-12-02 20:17:53 +03:00
|
|
|
|
|
|
|
p.setOpacity(1);
|
|
|
|
if (xadd || yadd) p.translate(-xadd, -yadd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::mousePressEvent(QMouseEvent *e) {
|
|
|
|
if (_saving) return;
|
|
|
|
if (_dragging >= 0) mouseReleaseEvent(e);
|
|
|
|
_mouse = e->globalPos();
|
|
|
|
onUpdateSelected();
|
2016-06-28 21:05:38 +03:00
|
|
|
|
|
|
|
_pressed = _selected;
|
|
|
|
if (_actionSel >= 0) {
|
|
|
|
_actionDown = _actionSel;
|
|
|
|
update(0, _itemsTop + _actionSel * _rowHeight, width(), _rowHeight);
|
2016-07-15 18:58:52 +03:00
|
|
|
} else if (_selected >= 0 && _section == Section::Installed && !_rows.at(_selected)->recent) {
|
2015-12-02 20:17:53 +03:00
|
|
|
_above = _dragging = _started = _selected;
|
|
|
|
_dragStart = mapFromGlobal(_mouse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
if (_saving) return;
|
|
|
|
_mouse = e->globalPos();
|
|
|
|
onUpdateSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::onUpdateSelected() {
|
|
|
|
if (_saving) return;
|
|
|
|
QPoint local(mapFromGlobal(_mouse));
|
|
|
|
if (_dragging >= 0) {
|
|
|
|
int32 shift = 0;
|
|
|
|
uint64 ms = getms();
|
2016-07-15 18:58:52 +03:00
|
|
|
int firstSetIndex = 0;
|
|
|
|
if (_rows.at(firstSetIndex)->recent) {
|
|
|
|
++firstSetIndex;
|
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
if (_dragStart.y() > local.y() && _dragging > 0) {
|
2016-07-15 18:58:52 +03:00
|
|
|
shift = -floorclamp(_dragStart.y() - local.y() + (_rowHeight / 2), _rowHeight, 0, _dragging - firstSetIndex);
|
2015-12-02 20:17:53 +03:00
|
|
|
for (int32 from = _dragging, to = _dragging + shift; from > to; --from) {
|
|
|
|
qSwap(_rows[from], _rows[from - 1]);
|
|
|
|
_rows.at(from)->yadd = anim::ivalue(_rows.at(from)->yadd.current() - _rowHeight, 0);
|
|
|
|
_animStartTimes[from] = ms;
|
|
|
|
}
|
|
|
|
} else if (_dragStart.y() < local.y() && _dragging + 1 < _rows.size()) {
|
|
|
|
shift = floorclamp(local.y() - _dragStart.y() + (_rowHeight / 2), _rowHeight, 0, _rows.size() - _dragging - 1);
|
|
|
|
for (int32 from = _dragging, to = _dragging + shift; from < to; ++from) {
|
|
|
|
qSwap(_rows[from], _rows[from + 1]);
|
|
|
|
_rows.at(from)->yadd = anim::ivalue(_rows.at(from)->yadd.current() + _rowHeight, 0);
|
|
|
|
_animStartTimes[from] = ms;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (shift) {
|
|
|
|
_dragging += shift;
|
|
|
|
_above = _dragging;
|
|
|
|
_dragStart.setY(_dragStart.y() + shift * _rowHeight);
|
|
|
|
if (!_a_shifting.animating()) {
|
|
|
|
_a_shifting.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_rows.at(_dragging)->yadd = anim::ivalue(local.y() - _dragStart.y(), local.y() - _dragStart.y());
|
|
|
|
_animStartTimes[_dragging] = 0;
|
2015-12-08 15:33:37 +03:00
|
|
|
_a_shifting.step(getms(), true);
|
2015-12-02 20:17:53 +03:00
|
|
|
|
|
|
|
emit checkDraggingScroll(local.y());
|
|
|
|
} else {
|
2015-12-06 18:50:02 +03:00
|
|
|
bool in = rect().marginsRemoved(QMargins(0, _itemsTop, 0, st::membersPadding.bottom())).contains(local);
|
2016-06-28 21:05:38 +03:00
|
|
|
int selected = -2;
|
|
|
|
int actionSel = -1;
|
|
|
|
if (in) {
|
|
|
|
selected = floorclamp(local.y() - _itemsTop, _rowHeight, 0, _rows.size() - 1);
|
|
|
|
|
|
|
|
if (_section == Section::Installed) {
|
2016-07-15 18:58:52 +03:00
|
|
|
int remw = _rows.at(selected)->recent ? _clearWidth : (_rows.at(selected)->disabled ? (_rows.at(selected)->official ? _restoreWidth : _returnWidth) : _removeWidth);
|
2016-06-28 21:05:38 +03:00
|
|
|
QRect rem(myrtlrect(width() - st::contactsPadding.right() - st::contactsCheckPosition.x() - remw, st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, remw, st::normalFont->height));
|
|
|
|
actionSel = rem.contains(local.x(), local.y() - _itemsTop - selected * _rowHeight) ? selected : -1;
|
2016-07-18 18:39:10 +03:00
|
|
|
} else if (_rows.at(selected)->installed && !_rows.at(selected)->disabled) {
|
2016-06-28 21:05:38 +03:00
|
|
|
actionSel = -1;
|
|
|
|
} else {
|
2016-07-18 18:39:10 +03:00
|
|
|
int addw = st::stickersAddSize.width();
|
2016-06-28 21:05:38 +03:00
|
|
|
int addx = width() - st::contactsPadding.right() - st::contactsCheckPosition.x() - addw;
|
2016-07-18 18:39:10 +03:00
|
|
|
int addy = st::contactsPadding.top() + (st::contactsPhotoSize - st::stickersAddSize.height()) / 2;
|
|
|
|
QRect add(myrtlrect(addx, addy, addw, st::stickersAddSize.height()));
|
2016-06-28 21:05:38 +03:00
|
|
|
actionSel = add.contains(local.x(), local.y() - _itemsTop - selected * _rowHeight) ? selected : -1;
|
|
|
|
}
|
2016-07-21 16:57:31 +03:00
|
|
|
} else if (_hasFeaturedButton && QRect(0, st::membersPadding.top(), width(), _buttonHeight).contains(local)) {
|
|
|
|
selected = -2;
|
|
|
|
} else if (_hasArchivedButton && QRect(0, st::membersPadding.top() + (_hasFeaturedButton ? _buttonHeight : 0), width(), _buttonHeight).contains(local)) {
|
2016-06-28 21:05:38 +03:00
|
|
|
selected = -1;
|
|
|
|
} else {
|
2016-07-21 16:57:31 +03:00
|
|
|
selected = -3;
|
2016-06-28 21:05:38 +03:00
|
|
|
}
|
|
|
|
if (_selected != selected) {
|
2016-07-21 16:57:31 +03:00
|
|
|
if (((_selected == -1) != (selected == -1)) || ((_selected == -2) != (selected == -2))) {
|
2016-06-28 21:05:38 +03:00
|
|
|
update();
|
|
|
|
}
|
2016-07-18 18:39:10 +03:00
|
|
|
if (_section != Section::Installed && ((_selected >= 0 || _pressed >= 0) != (selected >= 0 || _pressed >= 0))) {
|
2016-06-28 21:05:38 +03:00
|
|
|
setCursor((selected >= 0 || _pressed >= 0) ? style::cur_pointer : style::cur_default);
|
|
|
|
}
|
|
|
|
_selected = selected;
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
setActionSel(actionSel);
|
2015-12-02 20:17:53 +03:00
|
|
|
emit noDraggingScroll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-15 18:58:52 +03:00
|
|
|
void StickersInner::onClearRecent() {
|
|
|
|
if (_clearBox) {
|
|
|
|
_clearBox->onClose();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &sets = Global::RefStickerSets();
|
2016-07-21 13:09:47 +03:00
|
|
|
bool removedCloud = (sets.remove(Stickers::CloudRecentSetId) != 0);
|
|
|
|
bool removedCustom = (sets.remove(Stickers::CustomSetId) != 0);
|
2016-07-15 18:58:52 +03:00
|
|
|
|
|
|
|
auto &recent = cGetRecentStickers();
|
|
|
|
if (!recent.isEmpty()) {
|
|
|
|
recent.clear();
|
|
|
|
Local::writeUserSettings();
|
|
|
|
}
|
|
|
|
|
2016-07-21 13:09:47 +03:00
|
|
|
if (removedCustom) Local::writeInstalledStickers();
|
|
|
|
if (removedCloud) Local::writeRecentStickers();
|
2016-07-15 18:58:52 +03:00
|
|
|
emit App::main()->updateStickers();
|
|
|
|
rebuild();
|
|
|
|
|
|
|
|
MTP::send(MTPmessages_ClearRecentStickers());
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::onClearBoxDestroyed(QObject *box) {
|
|
|
|
if (box == _clearBox) {
|
|
|
|
_clearBox = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-02 20:17:53 +03:00
|
|
|
float64 StickersInner::aboveShadowOpacity() const {
|
|
|
|
if (_above < 0) return 0;
|
2016-01-09 19:24:16 +08:00
|
|
|
|
2015-12-05 15:37:08 +03:00
|
|
|
int32 dx = 0;
|
|
|
|
int32 dy = qAbs(_above * _rowHeight + _rows.at(_above)->yadd.current() - _started * _rowHeight);
|
2015-12-02 20:17:53 +03:00
|
|
|
return qMin((dx + dy) * 2. / _rowHeight, 1.);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::mouseReleaseEvent(QMouseEvent *e) {
|
2016-06-28 21:05:38 +03:00
|
|
|
auto pressed = _pressed;
|
|
|
|
_pressed = -2;
|
|
|
|
|
2016-07-18 18:39:10 +03:00
|
|
|
if (_section != Section::Installed && _selected < 0 && pressed >= 0) {
|
2016-06-28 21:05:38 +03:00
|
|
|
setCursor(style::cur_default);
|
|
|
|
}
|
|
|
|
|
2015-12-02 20:17:53 +03:00
|
|
|
if (_saving) return;
|
2016-06-28 21:05:38 +03:00
|
|
|
|
2015-12-02 20:17:53 +03:00
|
|
|
_mouse = e->globalPos();
|
|
|
|
onUpdateSelected();
|
2016-06-28 21:05:38 +03:00
|
|
|
if (_actionDown == _actionSel && _actionSel >= 0) {
|
|
|
|
if (_section == Section::Installed) {
|
2016-07-15 18:58:52 +03:00
|
|
|
if (_rows[_actionDown]->recent) {
|
|
|
|
_clearBox = new ConfirmBox(lang(lng_stickers_clear_recent_sure), lang(lng_stickers_clear_recent));
|
|
|
|
connect(_clearBox, SIGNAL(confirmed()), this, SLOT(onClearRecent()));
|
|
|
|
connect(_clearBox, SIGNAL(destroyed(QObject*)), this, SLOT(onClearBoxDestroyed(QObject*)));
|
|
|
|
Ui::showLayer(_clearBox, KeepOtherLayers);
|
|
|
|
} else {
|
|
|
|
_rows[_actionDown]->disabled = !_rows[_actionDown]->disabled;
|
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
} else {
|
|
|
|
installSet(_rows[_actionDown]->id);
|
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
} else if (_dragging >= 0) {
|
|
|
|
QPoint local(mapFromGlobal(_mouse));
|
|
|
|
_rows[_dragging]->yadd.start(0);
|
|
|
|
_aboveShadowFadeStart = _animStartTimes[_dragging] = getms();
|
|
|
|
_aboveShadowFadeOpacity = anim::fvalue(aboveShadowOpacity(), 0);
|
|
|
|
if (!_a_shifting.animating()) {
|
|
|
|
_a_shifting.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
_dragging = _started = -1;
|
2016-07-08 20:24:48 +03:00
|
|
|
} else if (pressed == _selected && _actionSel < 0 && _actionDown < 0) {
|
2016-07-21 16:57:31 +03:00
|
|
|
if (_selected == -2) {
|
|
|
|
_selected = -3;
|
2016-06-28 21:05:38 +03:00
|
|
|
Ui::showLayer(new StickersBox(Section::Featured), KeepOtherLayers);
|
2016-07-21 16:57:31 +03:00
|
|
|
} else if (_selected == -1) {
|
|
|
|
_selected = -3;
|
|
|
|
Ui::showLayer(new StickersBox(Section::Archived), KeepOtherLayers);
|
2016-07-18 18:39:10 +03:00
|
|
|
} else if (_selected >= 0 && _section != Section::Installed) {
|
2016-06-28 21:05:38 +03:00
|
|
|
auto &sets = Global::RefStickerSets();
|
|
|
|
auto it = sets.find(_rows.at(pressed)->id);
|
|
|
|
if (it != sets.cend()) {
|
2016-07-21 16:57:31 +03:00
|
|
|
_selected = -3;
|
2016-06-28 21:05:38 +03:00
|
|
|
Ui::showLayer(new StickerSetBox(Stickers::inputSetId(*it)), KeepOtherLayers);
|
|
|
|
}
|
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
if (_actionDown >= 0) {
|
|
|
|
update(0, _itemsTop + _actionDown * _rowHeight, width(), _rowHeight);
|
|
|
|
_actionDown = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::leaveEvent(QEvent *e) {
|
|
|
|
_mouse = QPoint(-1, -1);
|
|
|
|
onUpdateSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::installSet(uint64 setId) {
|
|
|
|
auto &sets = Global::RefStickerSets();
|
|
|
|
auto it = sets.find(setId);
|
|
|
|
if (it == sets.cend()) {
|
|
|
|
rebuild();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-18 18:39:10 +03:00
|
|
|
MTP::send(MTPmessages_InstallStickerSet(Stickers::inputSetId(*it), MTP_boolFalse()), rpcDone(&StickersInner::installDone), rpcFail(&StickersInner::installFail, setId));
|
2016-06-28 21:05:38 +03:00
|
|
|
|
2016-09-09 18:52:46 +03:00
|
|
|
Stickers::installLocally(setId);
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
|
2016-07-18 18:39:10 +03:00
|
|
|
void StickersInner::installDone(const MTPmessages_StickerSetInstallResult &result) {
|
|
|
|
if (result.type() == mtpc_messages_stickerSetInstallResultArchive) {
|
|
|
|
Stickers::applyArchivedResult(result.c_messages_stickerSetInstallResultArchive());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-14 14:59:55 +03:00
|
|
|
bool StickersInner::installFail(uint64 setId, const RPCError &error) {
|
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
|
|
|
|
|
|
|
auto &sets = Global::RefStickerSets();
|
|
|
|
auto it = sets.find(setId);
|
|
|
|
if (it == sets.cend()) {
|
|
|
|
rebuild();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-09 18:52:46 +03:00
|
|
|
Stickers::undoInstallLocally(setId);
|
2016-07-14 14:59:55 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-08 15:33:37 +03:00
|
|
|
void StickersInner::step_shifting(uint64 ms, bool timer) {
|
2015-12-05 15:37:08 +03:00
|
|
|
bool animating = false;
|
2015-12-08 15:33:37 +03:00
|
|
|
int32 updateMin = -1, updateMax = 0;
|
2015-12-05 15:37:08 +03:00
|
|
|
for (int32 i = 0, l = _animStartTimes.size(); i < l; ++i) {
|
|
|
|
uint64 start = _animStartTimes.at(i);
|
|
|
|
if (start) {
|
2015-12-08 15:33:37 +03:00
|
|
|
if (updateMin < 0) updateMin = i;
|
|
|
|
updateMax = i;
|
2015-12-05 15:37:08 +03:00
|
|
|
if (start + st::stickersRowDuration > ms && ms >= start) {
|
2016-06-15 20:13:46 +03:00
|
|
|
_rows.at(i)->yadd.update(float64(ms - start) / st::stickersRowDuration, anim::sineInOut);
|
2015-12-02 20:17:53 +03:00
|
|
|
animating = true;
|
|
|
|
} else {
|
|
|
|
_rows.at(i)->yadd.finish();
|
|
|
|
_animStartTimes[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_aboveShadowFadeStart) {
|
2015-12-08 15:33:37 +03:00
|
|
|
if (updateMin < 0 || updateMin > _above) updateMin = _above;
|
|
|
|
if (updateMax < _above) updateMin = _above;
|
2015-12-02 20:17:53 +03:00
|
|
|
if (_aboveShadowFadeStart + st::stickersRowDuration > ms && ms > _aboveShadowFadeStart) {
|
2016-06-15 20:13:46 +03:00
|
|
|
_aboveShadowFadeOpacity.update(float64(ms - _aboveShadowFadeStart) / st::stickersRowDuration, anim::sineInOut);
|
2015-12-02 20:17:53 +03:00
|
|
|
animating = true;
|
|
|
|
} else {
|
|
|
|
_aboveShadowFadeOpacity.finish();
|
|
|
|
_aboveShadowFadeStart = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-12-08 15:33:37 +03:00
|
|
|
if (timer) {
|
|
|
|
if (_dragging >= 0) {
|
|
|
|
if (updateMin < 0 || updateMin > _dragging) updateMin = _dragging;
|
|
|
|
if (updateMax < _dragging) updateMax = _dragging;
|
|
|
|
}
|
|
|
|
if (updateMin >= 0) {
|
|
|
|
update(0, _itemsTop + _rowHeight * (updateMin - 1), width(), _rowHeight * (updateMax - updateMin + 3));
|
|
|
|
}
|
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
if (!animating) {
|
|
|
|
_above = _dragging;
|
2015-12-08 15:33:37 +03:00
|
|
|
_a_shifting.stop();
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::clear() {
|
|
|
|
for (int32 i = 0, l = _rows.size(); i < l; ++i) {
|
|
|
|
delete _rows.at(i);
|
|
|
|
}
|
|
|
|
_rows.clear();
|
|
|
|
_animStartTimes.clear();
|
|
|
|
_aboveShadowFadeStart = 0;
|
|
|
|
_aboveShadowFadeOpacity = anim::fvalue(0, 0);
|
|
|
|
_a_shifting.stop();
|
2016-07-18 18:39:10 +03:00
|
|
|
_above = _dragging = _started = -1;
|
2016-07-21 16:57:31 +03:00
|
|
|
_selected = -3;
|
|
|
|
_pressed = -3;
|
2016-07-18 18:39:10 +03:00
|
|
|
_actionDown = -1;
|
|
|
|
setActionSel(-1);
|
|
|
|
update();
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
|
2016-06-28 21:05:38 +03:00
|
|
|
void StickersInner::setActionSel(int32 actionSel) {
|
|
|
|
if (actionSel != _actionSel) {
|
|
|
|
if (_actionSel >= 0) update(0, _itemsTop + _actionSel * _rowHeight, width(), _rowHeight);
|
|
|
|
_actionSel = actionSel;
|
|
|
|
if (_actionSel >= 0) update(0, _itemsTop + _actionSel * _rowHeight, width(), _rowHeight);
|
|
|
|
if (_section == Section::Installed) {
|
|
|
|
setCursor((_actionSel >= 0 && (_actionDown < 0 || _actionDown == _actionSel)) ? style::cur_pointer : style::cur_default);
|
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::rebuild() {
|
2016-07-21 16:57:31 +03:00
|
|
|
_hasFeaturedButton = _hasArchivedButton = false;
|
2016-06-28 21:05:38 +03:00
|
|
|
_itemsTop = st::membersPadding.top();
|
2016-07-21 16:57:31 +03:00
|
|
|
_buttonHeight = st::stickersFeaturedHeight;
|
2016-06-28 21:05:38 +03:00
|
|
|
if (_section == Section::Installed) {
|
2016-07-21 16:57:31 +03:00
|
|
|
if (!Global::FeaturedStickerSetsOrder().isEmpty()) {
|
|
|
|
_itemsTop += _buttonHeight;
|
|
|
|
_hasFeaturedButton = true;
|
|
|
|
}
|
|
|
|
if (!Global::ArchivedStickerSetsOrder().isEmpty()) {
|
|
|
|
_itemsTop += _buttonHeight;
|
|
|
|
_hasArchivedButton = true;
|
|
|
|
}
|
|
|
|
if (_itemsTop > st::membersPadding.top()) {
|
|
|
|
_itemsTop += st::membersPadding.top();
|
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
|
2016-07-21 16:57:31 +03:00
|
|
|
int maxNameWidth = countMaxNameWidth();
|
|
|
|
|
2015-12-02 20:17:53 +03:00
|
|
|
clear();
|
2016-07-27 21:36:45 +03:00
|
|
|
auto &order = ([this]() -> const Stickers::Order & {
|
2016-07-18 18:39:10 +03:00
|
|
|
if (_section == Section::Installed) {
|
|
|
|
return Global::StickerSetsOrder();
|
|
|
|
} else if (_section == Section::Featured) {
|
|
|
|
return Global::FeaturedStickerSetsOrder();
|
2016-07-21 16:57:31 +03:00
|
|
|
} else if (_section == Section::Archived) {
|
|
|
|
return Global::ArchivedStickerSetsOrder();
|
2016-07-18 18:39:10 +03:00
|
|
|
}
|
|
|
|
return _archivedIds;
|
|
|
|
})();
|
|
|
|
_rows.reserve(order.size() + 1);
|
|
|
|
_animStartTimes.reserve(order.size() + 1);
|
2016-01-09 19:24:16 +08:00
|
|
|
|
2016-06-27 19:25:21 +03:00
|
|
|
auto &sets = Global::StickerSets();
|
2016-07-18 18:39:10 +03:00
|
|
|
if (_section == Section::Installed) {
|
|
|
|
auto cloudIt = sets.constFind(Stickers::CloudRecentSetId);
|
|
|
|
if (cloudIt != sets.cend() && !cloudIt->stickers.isEmpty()) {
|
2016-07-21 16:57:31 +03:00
|
|
|
rebuildAppendSet(cloudIt.value(), maxNameWidth);
|
2016-07-15 18:58:52 +03:00
|
|
|
}
|
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
for_const (auto setId, order) {
|
|
|
|
auto it = sets.constFind(setId);
|
|
|
|
if (it == sets.cend()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:57:31 +03:00
|
|
|
rebuildAppendSet(it.value(), maxNameWidth);
|
2016-06-28 21:05:38 +03:00
|
|
|
|
|
|
|
if (it->stickers.isEmpty() || (it->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) {
|
|
|
|
App::api()->scheduleStickerSetRequest(it->id, it->access);
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
App::api()->requestStickerSets();
|
2016-07-21 16:57:31 +03:00
|
|
|
updateSize();
|
2016-06-28 21:05:38 +03:00
|
|
|
|
|
|
|
if (_section == Section::Featured && Global::FeaturedStickerSetsUnreadCount()) {
|
|
|
|
Global::SetFeaturedStickerSetsUnreadCount(0);
|
2016-09-07 12:04:57 +03:00
|
|
|
QVector<MTPlong> readIds;
|
|
|
|
readIds.reserve(Global::StickerSets().size());
|
2016-06-28 21:05:38 +03:00
|
|
|
for (auto &set : Global::RefStickerSets()) {
|
2016-09-07 12:04:57 +03:00
|
|
|
if (set.flags & MTPDstickerSet_ClientFlag::f_unread) {
|
|
|
|
set.flags &= ~MTPDstickerSet_ClientFlag::f_unread;
|
|
|
|
readIds.push_back(MTP_long(set.id));
|
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
}
|
2016-09-07 12:04:57 +03:00
|
|
|
MTP::send(MTPmessages_ReadFeaturedStickers(MTP_vector<MTPlong>(readIds)), rpcDone(&StickersInner::readFeaturedDone), rpcFail(&StickersInner::readFeaturedFail));
|
2016-06-28 21:05:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:57:31 +03:00
|
|
|
void StickersInner::updateSize() {
|
|
|
|
resize(width(), _itemsTop + _rows.size() * _rowHeight + st::membersPadding.bottom());
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::updateRows() {
|
|
|
|
int maxNameWidth = countMaxNameWidth();
|
|
|
|
auto &sets = Global::StickerSets();
|
|
|
|
for_const (auto row, _rows) {
|
|
|
|
auto it = sets.constFind(row->id);
|
|
|
|
if (it != sets.cend()) {
|
|
|
|
auto &set = it.value();
|
|
|
|
if (!row->sticker) {
|
|
|
|
DocumentData *sticker = nullptr;
|
|
|
|
int pixw = 0, pixh = 0;
|
|
|
|
fillSetCover(set, &sticker, &pixw, &pixh);
|
|
|
|
if (sticker) {
|
|
|
|
row->sticker = sticker;
|
|
|
|
row->pixw = pixw;
|
|
|
|
row->pixh = pixh;
|
|
|
|
}
|
2016-07-18 18:39:10 +03:00
|
|
|
}
|
2016-07-21 16:57:31 +03:00
|
|
|
fillSetFlags(set, &row->recent, &row->installed, &row->official, &row->unread, &row->disabled);
|
|
|
|
if (_section == Section::Installed) {
|
|
|
|
row->disabled = false;
|
|
|
|
}
|
|
|
|
row->title = fillSetTitle(set, maxNameWidth);
|
|
|
|
row->count = fillSetCount(set);
|
2016-07-18 18:39:10 +03:00
|
|
|
}
|
|
|
|
}
|
2016-07-21 16:57:31 +03:00
|
|
|
update();
|
|
|
|
}
|
2016-07-18 18:39:10 +03:00
|
|
|
|
2016-07-21 16:57:31 +03:00
|
|
|
bool StickersInner::appendSet(const Stickers::Set &set) {
|
|
|
|
for_const (auto row, _rows) {
|
|
|
|
if (row->id == set.id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rebuildAppendSet(set, countMaxNameWidth());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int StickersInner::countMaxNameWidth() const {
|
|
|
|
int namex = st::contactsPadding.left() + st::contactsPhotoSize + st::contactsPadding.left();
|
|
|
|
int namew = st::boxWideWidth - namex - st::contactsPadding.right() - st::contactsCheckPosition.x();
|
|
|
|
if (_section == Section::Installed) {
|
|
|
|
namew -= qMax(qMax(qMax(_returnWidth, _removeWidth), _restoreWidth), _clearWidth);
|
|
|
|
} else {
|
2016-07-26 15:09:40 +03:00
|
|
|
namew -= st::stickersAddIcon.width() - st::defaultActiveButton.width;
|
2016-07-21 16:57:31 +03:00
|
|
|
}
|
|
|
|
return namew;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::rebuildAppendSet(const Stickers::Set &set, int maxNameWidth) {
|
|
|
|
bool recent = false, installed = false, official = false, unread = false, disabled = false;
|
|
|
|
fillSetFlags(set, &recent, &installed, &official, &unread, &disabled);
|
|
|
|
if (_section == Section::Installed && disabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData *sticker = nullptr;
|
|
|
|
int pixw = 0, pixh = 0;
|
|
|
|
fillSetCover(set, &sticker, &pixw, &pixh);
|
|
|
|
|
|
|
|
QString title = fillSetTitle(set, maxNameWidth);
|
|
|
|
int count = fillSetCount(set);
|
|
|
|
|
|
|
|
_rows.push_back(new StickerSetRow(set.id, sticker, count, title, installed, official, unread, disabled, recent, pixw, pixh));
|
|
|
|
_animStartTimes.push_back(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::fillSetCover(const Stickers::Set &set, DocumentData **outSticker, int *outWidth, int *outHeight) const {
|
|
|
|
if (set.stickers.isEmpty()) {
|
|
|
|
*outSticker = nullptr;
|
|
|
|
*outWidth = *outHeight = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto sticker = *outSticker = set.stickers.front();
|
|
|
|
|
|
|
|
auto pixw = sticker->thumb->width();
|
|
|
|
auto pixh = sticker->thumb->height();
|
|
|
|
if (pixw > st::contactsPhotoSize) {
|
|
|
|
if (pixw > pixh) {
|
|
|
|
pixh = (pixh * st::contactsPhotoSize) / pixw;
|
|
|
|
pixw = st::contactsPhotoSize;
|
|
|
|
} else {
|
2016-07-18 18:39:10 +03:00
|
|
|
pixw = (pixw * st::contactsPhotoSize) / pixh;
|
|
|
|
pixh = st::contactsPhotoSize;
|
|
|
|
}
|
2016-07-21 16:57:31 +03:00
|
|
|
} else if (pixh > st::contactsPhotoSize) {
|
|
|
|
pixw = (pixw * st::contactsPhotoSize) / pixh;
|
|
|
|
pixh = st::contactsPhotoSize;
|
2016-07-18 18:39:10 +03:00
|
|
|
}
|
2016-07-21 16:57:31 +03:00
|
|
|
*outWidth = pixw;
|
|
|
|
*outHeight = pixh;
|
|
|
|
}
|
|
|
|
|
|
|
|
int StickersInner::fillSetCount(const Stickers::Set &set) const {
|
|
|
|
int result = set.stickers.isEmpty() ? set.count : set.stickers.size(), added = 0;
|
|
|
|
if (set.id == Stickers::CloudRecentSetId) {
|
2016-07-18 18:39:10 +03:00
|
|
|
auto customIt = Global::StickerSets().constFind(Stickers::CustomSetId);
|
|
|
|
if (customIt != Global::StickerSets().cend()) {
|
|
|
|
added = customIt->stickers.size();
|
|
|
|
for_const (auto &sticker, cGetRecentStickers()) {
|
|
|
|
if (customIt->stickers.indexOf(sticker.first) < 0) {
|
|
|
|
++added;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
added = cGetRecentStickers().size();
|
|
|
|
}
|
|
|
|
}
|
2016-07-21 16:57:31 +03:00
|
|
|
return result + added;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString StickersInner::fillSetTitle(const Stickers::Set &set, int maxNameWidth) const {
|
|
|
|
auto result = set.title;
|
|
|
|
int32 titleWidth = st::contactsNameFont->width(result);
|
|
|
|
if (titleWidth > maxNameWidth) {
|
|
|
|
result = st::contactsNameFont->elided(result, maxNameWidth);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::fillSetFlags(const Stickers::Set &set, bool *outRecent, bool *outInstalled, bool *outOfficial, bool *outUnread, bool *outDisabled) {
|
|
|
|
*outRecent = (set.id == Stickers::CloudRecentSetId);
|
|
|
|
*outInstalled = true;
|
|
|
|
*outOfficial = true;
|
|
|
|
*outUnread = false;
|
|
|
|
*outDisabled = false;
|
|
|
|
if (!*outRecent) {
|
|
|
|
*outInstalled = (set.flags & MTPDstickerSet::Flag::f_installed);
|
|
|
|
*outOfficial = (set.flags & MTPDstickerSet::Flag::f_official);
|
|
|
|
*outDisabled = (set.flags & MTPDstickerSet::Flag::f_archived);
|
|
|
|
if (_section == Section::Featured) {
|
|
|
|
*outUnread = _unreadSets.contains(set.id);
|
|
|
|
if (!*outUnread && (set.flags & MTPDstickerSet_ClientFlag::f_unread)) {
|
|
|
|
*outUnread = true;
|
|
|
|
_unreadSets.insert(set.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-18 18:39:10 +03:00
|
|
|
}
|
|
|
|
|
2016-06-28 21:05:38 +03:00
|
|
|
void StickersInner::readFeaturedDone(const MTPBool &result) {
|
2016-07-21 13:09:47 +03:00
|
|
|
Local::writeFeaturedStickers();
|
2016-06-28 21:05:38 +03:00
|
|
|
emit App::main()->stickersUpdated();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StickersInner::readFeaturedFail(const RPCError &error) {
|
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
|
|
|
|
|
|
|
int unreadCount = 0;
|
|
|
|
for_const (auto &set, Global::StickerSets()) {
|
|
|
|
if (!(set.flags & MTPDstickerSet::Flag::f_installed)) {
|
|
|
|
if (set.flags & MTPDstickerSet_ClientFlag::f_unread) {
|
|
|
|
++unreadCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Global::SetFeaturedStickerSetsUnreadCount(unreadCount);
|
|
|
|
return true;
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
|
2016-07-18 18:39:10 +03:00
|
|
|
Stickers::Order StickersInner::getOrder() const {
|
|
|
|
Stickers::Order result;
|
2015-12-02 20:17:53 +03:00
|
|
|
result.reserve(_rows.size());
|
|
|
|
for (int32 i = 0, l = _rows.size(); i < l; ++i) {
|
2016-07-21 13:09:47 +03:00
|
|
|
if (_rows.at(i)->disabled || _rows.at(i)->recent) {
|
2016-07-15 18:58:52 +03:00
|
|
|
continue;
|
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
result.push_back(_rows.at(i)->id);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-07-18 18:39:10 +03:00
|
|
|
Stickers::Order StickersInner::getDisabledSets() const {
|
|
|
|
Stickers::Order result;
|
2015-12-02 20:17:53 +03:00
|
|
|
result.reserve(_rows.size());
|
|
|
|
for (int32 i = 0, l = _rows.size(); i < l; ++i) {
|
|
|
|
if (_rows.at(i)->disabled) {
|
|
|
|
result.push_back(_rows.at(i)->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersInner::setVisibleScrollbar(int32 width) {
|
|
|
|
_scrollbar = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
StickersInner::~StickersInner() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2016-06-28 21:05:38 +03:00
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
StickersBox::StickersBox(Section section) : ItemListBox(st::boxScroll)
|
|
|
|
, _section(section)
|
|
|
|
, _inner(section)
|
2016-07-26 12:17:44 +03:00
|
|
|
, _aboutWidth(st::boxWideWidth - 2 * st::stickersReorderPadding.top())
|
2016-07-21 16:57:31 +03:00
|
|
|
, _about(st::boxTextFont, lang((section == Section::Archived) ? lng_stickers_packs_archived : lng_stickers_reorder), _defaultOptions, _aboutWidth) {
|
2016-07-18 18:39:10 +03:00
|
|
|
setup();
|
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
|
2016-07-18 18:39:10 +03:00
|
|
|
StickersBox::StickersBox(const Stickers::Order &archivedIds) : ItemListBox(st::boxScroll)
|
|
|
|
, _section(Section::ArchivedPart)
|
|
|
|
, _inner(archivedIds)
|
2016-07-26 12:17:44 +03:00
|
|
|
, _aboutWidth(st::boxWideWidth - 2 * st::stickersReorderPadding.top())
|
2016-07-18 18:39:10 +03:00
|
|
|
, _about(st::boxTextFont, lang(lng_stickers_packs_archived), _defaultOptions, _aboutWidth) {
|
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:57:31 +03:00
|
|
|
void StickersBox::getArchivedDone(uint64 offsetId, const MTPmessages_ArchivedStickers &result) {
|
|
|
|
_archivedRequestId = 0;
|
|
|
|
if (result.type() != mtpc_messages_archivedStickers) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &stickers = result.c_messages_archivedStickers();
|
|
|
|
auto &archived = Global::RefArchivedStickerSetsOrder();
|
|
|
|
if (offsetId) {
|
|
|
|
auto index = archived.indexOf(offsetId);
|
|
|
|
if (index >= 0) {
|
|
|
|
archived = archived.mid(0, index + 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
archived.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool addedSet = false;
|
|
|
|
auto &v = stickers.vsets.c_vector().v;
|
|
|
|
for_const (auto &stickerSet, v) {
|
2016-09-07 12:04:57 +03:00
|
|
|
const MTPDstickerSet *setData = nullptr;
|
|
|
|
switch (stickerSet.type()) {
|
|
|
|
case mtpc_stickerSetCovered: {
|
|
|
|
auto &d = stickerSet.c_stickerSetCovered();
|
|
|
|
if (d.vset.type() == mtpc_stickerSet) {
|
|
|
|
setData = &d.vset.c_stickerSet();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_stickerSetMultiCovered: {
|
|
|
|
auto &d = stickerSet.c_stickerSetMultiCovered();
|
|
|
|
if (d.vset.type() == mtpc_stickerSet) {
|
|
|
|
setData = &d.vset.c_stickerSet();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
if (!setData) continue;
|
2016-07-21 16:57:31 +03:00
|
|
|
|
2016-09-07 12:04:57 +03:00
|
|
|
if (auto set = Stickers::feedSet(*setData)) {
|
2016-07-21 16:57:31 +03:00
|
|
|
auto index = archived.indexOf(set->id);
|
2016-07-22 14:59:35 +03:00
|
|
|
if (archived.isEmpty() || index != archived.size() - 1) {
|
2016-07-21 16:57:31 +03:00
|
|
|
if (index < archived.size() - 1) {
|
|
|
|
archived.removeAt(index);
|
|
|
|
}
|
|
|
|
archived.push_back(set->id);
|
|
|
|
}
|
|
|
|
if (_section == Section::Archived) {
|
|
|
|
if (_inner->appendSet(*set)) {
|
|
|
|
addedSet = true;
|
|
|
|
if (set->stickers.isEmpty() || (set->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) {
|
|
|
|
App::api()->scheduleStickerSetRequest(set->id, set->access);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_section == Section::Installed && !archived.isEmpty()) {
|
|
|
|
Local::writeArchivedStickers();
|
|
|
|
rebuildList();
|
|
|
|
} else if (_section == Section::Archived) {
|
|
|
|
if (addedSet) {
|
|
|
|
_inner->updateSize();
|
|
|
|
setMaxHeight(snap(countHeight(), int32(st::sessionsHeight), int32(st::boxMaxListHeight)));
|
2016-09-06 15:28:37 +03:00
|
|
|
_inner->setVisibleScrollbar((scrollArea()->scrollTopMax() > 0) ? (st::boxScroll.width - st::boxScroll.deltax) : 0);
|
2016-07-21 16:57:31 +03:00
|
|
|
App::api()->requestStickerSets();
|
|
|
|
} else {
|
|
|
|
_allArchivedLoaded = v.isEmpty() || (offsetId != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkLoadMoreArchived();
|
|
|
|
}
|
|
|
|
|
2016-07-18 18:39:10 +03:00
|
|
|
void StickersBox::setup() {
|
2016-07-21 16:57:31 +03:00
|
|
|
if (_section == Section::Installed) {
|
|
|
|
Local::readArchivedStickers();
|
|
|
|
if (Global::ArchivedStickerSetsOrder().isEmpty()) {
|
|
|
|
_archivedRequestId = MTP::send(MTPmessages_GetArchivedStickers(MTP_long(0), MTP_int(kArchivedLimitFirstRequest)), rpcDone(&StickersBox::getArchivedDone, 0ULL));
|
|
|
|
}
|
|
|
|
} else if (_section == Section::Archived) {
|
|
|
|
// Reload the archived list.
|
|
|
|
_archivedRequestId = MTP::send(MTPmessages_GetArchivedStickers(MTP_long(0), MTP_int(kArchivedLimitFirstRequest)), rpcDone(&StickersBox::getArchivedDone, 0ULL));
|
|
|
|
|
|
|
|
auto &sets = Global::StickerSets();
|
|
|
|
for_const (auto setId, Global::ArchivedStickerSetsOrder()) {
|
|
|
|
auto it = sets.constFind(setId);
|
|
|
|
if (it != sets.cend()) {
|
|
|
|
if (it->stickers.isEmpty() && (it->flags & MTPDstickerSet_ClientFlag::f_not_loaded)) {
|
|
|
|
App::api()->scheduleStickerSetRequest(setId, it->access);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
App::api()->requestStickerSets();
|
|
|
|
}
|
|
|
|
|
2016-06-28 21:05:38 +03:00
|
|
|
int bottomSkip = st::boxPadding.bottom();
|
|
|
|
if (_section == Section::Installed) {
|
|
|
|
_aboutHeight = st::stickersReorderPadding.top() + _about.countHeight(_aboutWidth) + st::stickersReorderPadding.bottom();
|
2016-07-18 18:39:10 +03:00
|
|
|
_topShadow = new PlainShadow(this, st::contactsAboutShadow);
|
2016-06-28 21:05:38 +03:00
|
|
|
|
|
|
|
_save = new BoxButton(this, lang(lng_settings_save), st::defaultBoxButton);
|
|
|
|
connect(_save, SIGNAL(clicked()), this, SLOT(onSave()));
|
|
|
|
|
|
|
|
_cancel = new BoxButton(this, lang(lng_cancel), st::cancelBoxButton);
|
|
|
|
connect(_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
|
|
|
|
|
|
|
|
_bottomShadow = new ScrollableBoxShadow(this);
|
|
|
|
bottomSkip = st::boxButtonPadding.top() + _save->height() + st::boxButtonPadding.bottom();
|
2016-07-18 18:39:10 +03:00
|
|
|
} else if (_section == Section::ArchivedPart) {
|
|
|
|
_aboutHeight = st::stickersReorderPadding.top() + _about.countHeight(_aboutWidth) + st::stickersReorderPadding.bottom();
|
|
|
|
_topShadow = new PlainShadow(this, st::contactsAboutShadow);
|
|
|
|
|
|
|
|
_save = new BoxButton(this, lang(lng_box_ok), st::defaultBoxButton);
|
|
|
|
connect(_save, SIGNAL(clicked()), this, SLOT(onClose()));
|
2016-07-21 16:57:31 +03:00
|
|
|
} else if (_section == Section::Archived) {
|
|
|
|
_aboutHeight = st::stickersReorderPadding.top() + _about.countHeight(_aboutWidth) + st::stickersReorderPadding.bottom();
|
|
|
|
_topShadow = new PlainShadow(this, st::contactsAboutShadow);
|
2016-06-28 21:05:38 +03:00
|
|
|
}
|
|
|
|
ItemListBox::init(_inner, bottomSkip, st::boxTitleHeight + _aboutHeight);
|
2015-12-02 20:17:53 +03:00
|
|
|
setMaxHeight(snap(countHeight(), int32(st::sessionsHeight), int32(st::boxMaxListHeight)));
|
|
|
|
|
|
|
|
connect(App::main(), SIGNAL(stickersUpdated()), this, SLOT(onStickersUpdated()));
|
2016-01-11 12:45:07 +08:00
|
|
|
App::main()->updateStickers();
|
2015-12-02 20:17:53 +03:00
|
|
|
|
2016-06-28 21:05:38 +03:00
|
|
|
connect(_inner, SIGNAL(checkDraggingScroll(int)), this, SLOT(onCheckDraggingScroll(int)));
|
|
|
|
connect(_inner, SIGNAL(noDraggingScroll()), this, SLOT(onNoDraggingScroll()));
|
2015-12-02 20:17:53 +03:00
|
|
|
connect(&_scrollTimer, SIGNAL(timeout()), this, SLOT(onScrollTimer()));
|
2016-09-06 15:28:37 +03:00
|
|
|
connect(scrollArea(), SIGNAL(scrolled()), this, SLOT(onScroll()));
|
2015-12-02 20:17:53 +03:00
|
|
|
_scrollTimer.setSingleShot(false);
|
|
|
|
|
2016-07-21 16:57:31 +03:00
|
|
|
rebuildList();
|
2015-12-02 20:17:53 +03:00
|
|
|
|
|
|
|
prepare();
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:57:31 +03:00
|
|
|
void StickersBox::onScroll() {
|
|
|
|
checkLoadMoreArchived();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::checkLoadMoreArchived() {
|
|
|
|
if (_section != Section::Archived) return;
|
|
|
|
|
2016-09-06 15:28:37 +03:00
|
|
|
int scrollTop = scrollArea()->scrollTop(), scrollTopMax = scrollArea()->scrollTopMax();
|
|
|
|
if (scrollTop + PreloadHeightsCount * scrollArea()->height() >= scrollTopMax) {
|
2016-07-21 16:57:31 +03:00
|
|
|
if (!_archivedRequestId && !_allArchivedLoaded) {
|
|
|
|
uint64 lastId = 0;
|
|
|
|
for (auto setId = Global::ArchivedStickerSetsOrder().cend(), e = Global::ArchivedStickerSetsOrder().cbegin(); setId != e;) {
|
|
|
|
--setId;
|
|
|
|
auto it = Global::StickerSets().constFind(*setId);
|
|
|
|
if (it != Global::StickerSets().cend()) {
|
|
|
|
if (it->flags & MTPDstickerSet::Flag::f_archived) {
|
|
|
|
lastId = it->id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_archivedRequestId = MTP::send(MTPmessages_GetArchivedStickers(MTP_long(lastId), MTP_int(kArchivedLimitPerPage)), rpcDone(&StickersBox::getArchivedDone, lastId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-02 20:17:53 +03:00
|
|
|
int32 StickersBox::countHeight() const {
|
2016-06-28 21:05:38 +03:00
|
|
|
int bottomSkip = st::boxPadding.bottom();
|
|
|
|
if (_section == Section::Installed) {
|
|
|
|
bottomSkip = st::boxButtonPadding.top() + _save->height() + st::boxButtonPadding.bottom();
|
|
|
|
}
|
|
|
|
return st::boxTitleHeight + _aboutHeight + _inner->height() + bottomSkip;
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
|
2016-07-18 18:39:10 +03:00
|
|
|
void StickersBox::disenableDone(const MTPmessages_StickerSetInstallResult &result, mtpRequestId req) {
|
2015-12-02 20:17:53 +03:00
|
|
|
_disenableRequests.remove(req);
|
|
|
|
if (_disenableRequests.isEmpty()) {
|
|
|
|
saveOrder();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StickersBox::disenableFail(const RPCError &error, mtpRequestId req) {
|
2016-04-08 14:44:35 +04:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2015-12-02 20:17:53 +03:00
|
|
|
_disenableRequests.remove(req);
|
|
|
|
if (_disenableRequests.isEmpty()) {
|
|
|
|
saveOrder();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::saveOrder() {
|
2016-06-28 21:05:38 +03:00
|
|
|
auto order = _inner->getOrder();
|
2015-12-02 20:17:53 +03:00
|
|
|
if (order.size() > 1) {
|
|
|
|
QVector<MTPlong> mtpOrder;
|
|
|
|
mtpOrder.reserve(order.size());
|
2016-09-07 12:04:57 +03:00
|
|
|
for (int i = 0, l = order.size(); i < l; ++i) {
|
2015-12-02 20:17:53 +03:00
|
|
|
mtpOrder.push_back(MTP_long(order.at(i)));
|
|
|
|
}
|
2016-09-07 12:04:57 +03:00
|
|
|
|
|
|
|
MTPmessages_ReorderStickerSets::Flags flags = 0;
|
|
|
|
_reorderRequest = MTP::send(MTPmessages_ReorderStickerSets(MTP_flags(flags), MTP_vector<MTPlong>(mtpOrder)), rpcDone(&StickersBox::reorderDone), rpcFail(&StickersBox::reorderFail));
|
2015-12-02 20:17:53 +03:00
|
|
|
} else {
|
|
|
|
reorderDone(MTP_boolTrue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::reorderDone(const MTPBool &result) {
|
|
|
|
_reorderRequest = 0;
|
|
|
|
onClose();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StickersBox::reorderFail(const RPCError &result) {
|
2016-04-08 14:44:35 +04:00
|
|
|
if (MTP::isDefaultHandledError(result)) return false;
|
2015-12-02 20:17:53 +03:00
|
|
|
_reorderRequest = 0;
|
2016-03-19 19:55:15 +03:00
|
|
|
Global::SetLastStickersUpdate(0);
|
2015-12-02 20:17:53 +03:00
|
|
|
App::main()->updateStickers();
|
|
|
|
onClose();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
if (paint(p)) return;
|
|
|
|
|
2016-07-18 18:39:10 +03:00
|
|
|
auto title = ([this]() {
|
|
|
|
if (_section == Section::Installed) {
|
|
|
|
return lang(lng_stickers_packs);
|
|
|
|
} else if (_section == Section::Featured) {
|
|
|
|
return lang(lng_stickers_featured);
|
|
|
|
}
|
|
|
|
return lang(lng_stickers_archived);
|
|
|
|
})();
|
|
|
|
paintTitle(p, title);
|
2015-12-02 20:17:53 +03:00
|
|
|
p.translate(0, st::boxTitleHeight);
|
2015-12-06 18:50:02 +03:00
|
|
|
|
2016-06-28 21:05:38 +03:00
|
|
|
if (_aboutHeight > 0) {
|
|
|
|
p.fillRect(0, 0, width(), _aboutHeight, st::contactsAboutBg);
|
|
|
|
p.setPen(st::stickersReorderFg);
|
2016-07-26 12:17:44 +03:00
|
|
|
_about.draw(p, st::stickersReorderPadding.top(), st::stickersReorderPadding.top(), _aboutWidth, style::al_center);
|
2016-06-28 21:05:38 +03:00
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::closePressed() {
|
|
|
|
if (!_disenableRequests.isEmpty()) {
|
|
|
|
for (QMap<mtpRequestId, NullType>::const_iterator i = _disenableRequests.cbegin(), e = _disenableRequests.cend(); i != e; ++i) {
|
|
|
|
MTP::cancel(i.key());
|
|
|
|
}
|
|
|
|
_disenableRequests.clear();
|
2016-03-19 19:55:15 +03:00
|
|
|
Global::SetLastStickersUpdate(0);
|
2015-12-02 20:17:53 +03:00
|
|
|
App::main()->updateStickers();
|
|
|
|
} else if (_reorderRequest) {
|
|
|
|
MTP::cancel(_reorderRequest);
|
|
|
|
_reorderRequest = 0;
|
2016-03-19 19:55:15 +03:00
|
|
|
Global::SetLastStickersUpdate(0);
|
2015-12-02 20:17:53 +03:00
|
|
|
App::main()->updateStickers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 13:09:47 +03:00
|
|
|
StickersBox::~StickersBox() {
|
2016-07-21 16:57:31 +03:00
|
|
|
if (_section == Section::Archived) {
|
2016-07-21 13:09:47 +03:00
|
|
|
Local::writeArchivedStickers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-02 20:17:53 +03:00
|
|
|
void StickersBox::resizeEvent(QResizeEvent *e) {
|
|
|
|
ItemListBox::resizeEvent(e);
|
2016-06-28 21:05:38 +03:00
|
|
|
_inner->resize(width(), _inner->height());
|
2016-09-06 15:28:37 +03:00
|
|
|
_inner->setVisibleScrollbar((scrollArea()->scrollTopMax() > 0) ? (st::boxScroll.width - st::boxScroll.deltax) : 0);
|
2016-07-18 18:39:10 +03:00
|
|
|
if (_topShadow) {
|
|
|
|
_topShadow->setGeometry(0, st::boxTitleHeight + _aboutHeight, width(), st::lineWidth);
|
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
if (_save) {
|
|
|
|
_save->moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save->height());
|
2016-07-18 18:39:10 +03:00
|
|
|
}
|
|
|
|
if (_cancel) {
|
2016-06-28 21:05:38 +03:00
|
|
|
_cancel->moveToRight(st::boxButtonPadding.right() + _save->width() + st::boxButtonPadding.left(), _save->y());
|
|
|
|
_bottomShadow->setGeometry(0, height() - st::boxButtonPadding.bottom() - _save->height() - st::boxButtonPadding.top() - st::lineWidth, width(), st::lineWidth);
|
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::onStickersUpdated() {
|
2016-07-21 16:57:31 +03:00
|
|
|
if (_section == Section::Installed || _section == Section::Featured) {
|
|
|
|
rebuildList();
|
|
|
|
} else {
|
|
|
|
_inner->updateRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::rebuildList() {
|
2016-06-28 21:05:38 +03:00
|
|
|
_inner->rebuild();
|
2015-12-02 20:17:53 +03:00
|
|
|
setMaxHeight(snap(countHeight(), int32(st::sessionsHeight), int32(st::boxMaxListHeight)));
|
2016-09-06 15:28:37 +03:00
|
|
|
_inner->setVisibleScrollbar((scrollArea()->scrollTopMax() > 0) ? (st::boxScroll.width - st::boxScroll.deltax) : 0);
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::onCheckDraggingScroll(int localY) {
|
2016-09-06 15:28:37 +03:00
|
|
|
if (localY < scrollArea()->scrollTop()) {
|
|
|
|
_scrollDelta = localY - scrollArea()->scrollTop();
|
|
|
|
} else if (localY >= scrollArea()->scrollTop() + scrollArea()->height()) {
|
|
|
|
_scrollDelta = localY - scrollArea()->scrollTop() - scrollArea()->height() + 1;
|
2015-12-02 20:17:53 +03:00
|
|
|
} else {
|
|
|
|
_scrollDelta = 0;
|
|
|
|
}
|
|
|
|
if (_scrollDelta) {
|
|
|
|
_scrollTimer.start(15);
|
|
|
|
} else {
|
|
|
|
_scrollTimer.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::onNoDraggingScroll() {
|
|
|
|
_scrollTimer.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::onScrollTimer() {
|
|
|
|
int32 d = (_scrollDelta > 0) ? qMin(_scrollDelta * 3 / 20 + 1, int32(MaxScrollSpeed)) : qMax(_scrollDelta * 3 / 20 - 1, -int32(MaxScrollSpeed));
|
2016-09-06 15:28:37 +03:00
|
|
|
scrollArea()->scrollToY(scrollArea()->scrollTop() + d);
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::onSave() {
|
2016-06-28 21:05:38 +03:00
|
|
|
if (!_inner->savingStart()) {
|
2015-12-02 20:17:53 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:57:31 +03:00
|
|
|
bool writeRecent = false, writeArchived = false;
|
2016-07-15 18:58:52 +03:00
|
|
|
auto &recent = cGetRecentStickers();
|
2016-06-27 19:25:21 +03:00
|
|
|
auto &sets = Global::RefStickerSets();
|
2015-12-02 20:17:53 +03:00
|
|
|
|
2016-07-18 18:39:10 +03:00
|
|
|
auto reorder = _inner->getOrder(), disabled = _inner->getDisabledSets();
|
2015-12-02 20:17:53 +03:00
|
|
|
for (int32 i = 0, l = disabled.size(); i < l; ++i) {
|
2016-03-19 19:55:15 +03:00
|
|
|
auto it = sets.find(disabled.at(i));
|
2015-12-02 20:17:53 +03:00
|
|
|
if (it != sets.cend()) {
|
|
|
|
for (RecentStickerPack::iterator i = recent.begin(); i != recent.cend();) {
|
|
|
|
if (it->stickers.indexOf(i->first) >= 0) {
|
|
|
|
i = recent.erase(i);
|
|
|
|
writeRecent = true;
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2016-07-18 18:39:10 +03:00
|
|
|
if (!(it->flags & MTPDstickerSet::Flag::f_archived)) {
|
2015-12-02 20:17:53 +03:00
|
|
|
MTPInputStickerSet setId = (it->id && it->access) ? MTP_inputStickerSetID(MTP_long(it->id), MTP_long(it->access)) : MTP_inputStickerSetShortName(MTP_string(it->shortName));
|
2016-03-19 19:55:15 +03:00
|
|
|
if (it->flags & MTPDstickerSet::Flag::f_official) {
|
2015-12-02 20:17:53 +03:00
|
|
|
_disenableRequests.insert(MTP::send(MTPmessages_InstallStickerSet(setId, MTP_boolTrue()), rpcDone(&StickersBox::disenableDone), rpcFail(&StickersBox::disenableFail), 0, 5), NullType());
|
2016-07-18 18:39:10 +03:00
|
|
|
it->flags |= MTPDstickerSet::Flag::f_archived;
|
2016-07-21 16:57:31 +03:00
|
|
|
auto index = Global::RefArchivedStickerSetsOrder().indexOf(it->id);
|
|
|
|
if (index < 0) {
|
|
|
|
Global::RefArchivedStickerSetsOrder().push_front(it->id);
|
|
|
|
writeArchived = true;
|
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
} else {
|
|
|
|
_disenableRequests.insert(MTP::send(MTPmessages_UninstallStickerSet(setId), rpcDone(&StickersBox::disenableDone), rpcFail(&StickersBox::disenableFail), 0, 5), NullType());
|
2016-03-19 19:55:15 +03:00
|
|
|
int removeIndex = Global::StickerSetsOrder().indexOf(it->id);
|
|
|
|
if (removeIndex >= 0) Global::RefStickerSetsOrder().removeAt(removeIndex);
|
2016-07-15 18:58:52 +03:00
|
|
|
if (!(it->flags & MTPDstickerSet_ClientFlag::f_featured) && !(it->flags & MTPDstickerSet_ClientFlag::f_special)) {
|
2016-06-27 19:25:21 +03:00
|
|
|
sets.erase(it);
|
2016-06-28 21:05:38 +03:00
|
|
|
} else {
|
2016-07-21 16:57:31 +03:00
|
|
|
if (it->flags & MTPDstickerSet::Flag::f_archived) {
|
|
|
|
writeArchived = true;
|
|
|
|
}
|
2016-07-18 18:39:10 +03:00
|
|
|
it->flags &= ~(MTPDstickerSet::Flag::f_installed | MTPDstickerSet::Flag::f_archived);
|
2016-06-27 19:25:21 +03:00
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
|
|
|
|
// Clear all installed flags, set only for sets from order.
|
|
|
|
for (auto &set : sets) {
|
2016-07-21 13:09:47 +03:00
|
|
|
if (!(set.flags & MTPDstickerSet::Flag::f_archived)) {
|
|
|
|
set.flags &= ~MTPDstickerSet::Flag::f_installed;
|
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
auto &order(Global::RefStickerSetsOrder());
|
2015-12-02 20:17:53 +03:00
|
|
|
order.clear();
|
2016-03-19 19:55:15 +03:00
|
|
|
for (int i = 0, l = reorder.size(); i < l; ++i) {
|
|
|
|
auto it = sets.find(reorder.at(i));
|
2015-12-02 20:17:53 +03:00
|
|
|
if (it != sets.cend()) {
|
2016-07-18 18:39:10 +03:00
|
|
|
if ((it->flags & MTPDstickerSet::Flag::f_archived) && !disabled.contains(it->id)) {
|
2015-12-02 20:17:53 +03:00
|
|
|
MTPInputStickerSet setId = (it->id && it->access) ? MTP_inputStickerSetID(MTP_long(it->id), MTP_long(it->access)) : MTP_inputStickerSetShortName(MTP_string(it->shortName));
|
|
|
|
_disenableRequests.insert(MTP::send(MTPmessages_InstallStickerSet(setId, MTP_boolFalse()), rpcDone(&StickersBox::disenableDone), rpcFail(&StickersBox::disenableFail), 0, 5), NullType());
|
2016-07-18 18:39:10 +03:00
|
|
|
it->flags &= ~MTPDstickerSet::Flag::f_archived;
|
2016-07-21 16:57:31 +03:00
|
|
|
writeArchived = true;
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
order.push_back(reorder.at(i));
|
2016-06-28 21:05:38 +03:00
|
|
|
it->flags |= MTPDstickerSet::Flag::f_installed;
|
2015-12-02 20:17:53 +03:00
|
|
|
}
|
|
|
|
}
|
2016-03-19 19:55:15 +03:00
|
|
|
for (auto it = sets.begin(); it != sets.cend();) {
|
2016-07-15 18:58:52 +03:00
|
|
|
if ((it->flags & MTPDstickerSet_ClientFlag::f_featured)
|
|
|
|
|| (it->flags & MTPDstickerSet::Flag::f_installed)
|
2016-07-21 13:09:47 +03:00
|
|
|
|| (it->flags & MTPDstickerSet::Flag::f_archived)
|
2016-07-15 18:58:52 +03:00
|
|
|
|| (it->flags & MTPDstickerSet_ClientFlag::f_special)) {
|
2015-12-02 20:17:53 +03:00
|
|
|
++it;
|
|
|
|
} else {
|
|
|
|
it = sets.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 13:09:47 +03:00
|
|
|
Local::writeInstalledStickers();
|
2015-12-02 20:17:53 +03:00
|
|
|
if (writeRecent) Local::writeUserSettings();
|
2016-07-21 16:57:31 +03:00
|
|
|
if (writeArchived) Local::writeArchivedStickers();
|
2015-12-02 20:17:53 +03:00
|
|
|
emit App::main()->stickersUpdated();
|
|
|
|
|
|
|
|
if (_disenableRequests.isEmpty()) {
|
|
|
|
saveOrder();
|
|
|
|
} else {
|
|
|
|
MTP::sendAnything();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::showAll() {
|
2016-07-18 18:39:10 +03:00
|
|
|
if (_topShadow) {
|
|
|
|
_topShadow->show();
|
|
|
|
}
|
2016-06-28 21:05:38 +03:00
|
|
|
if (_save) {
|
|
|
|
_save->show();
|
2016-07-18 18:39:10 +03:00
|
|
|
}
|
|
|
|
if (_cancel) {
|
2016-06-28 21:05:38 +03:00
|
|
|
_cancel->show();
|
|
|
|
_bottomShadow->show();
|
|
|
|
}
|
2015-12-02 20:17:53 +03:00
|
|
|
ItemListBox::showAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 stickerPacksCount(bool includeDisabledOfficial) {
|
|
|
|
int32 result = 0;
|
2016-06-27 19:25:21 +03:00
|
|
|
auto &order = Global::StickerSetsOrder();
|
|
|
|
auto &sets = Global::StickerSets();
|
2016-03-19 19:55:15 +03:00
|
|
|
for (int i = 0, l = order.size(); i < l; ++i) {
|
|
|
|
auto it = sets.constFind(order.at(i));
|
2015-12-02 20:17:53 +03:00
|
|
|
if (it != sets.cend()) {
|
2016-07-18 18:39:10 +03:00
|
|
|
if (!(it->flags & MTPDstickerSet::Flag::f_archived) || ((it->flags & MTPDstickerSet::Flag::f_official) && includeDisabledOfficial)) {
|
2015-12-02 20:17:53 +03:00
|
|
|
++result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|