pausing of mtp while animating, fixed message field while animating

This commit is contained in:
John Preston 2015-10-15 12:18:24 +02:00
parent 1c28d59ed2
commit f12f21b16b
15 changed files with 99 additions and 2 deletions

View file

@ -296,6 +296,14 @@ void Application::cancelPhotoUpdate(const PeerId &peer) {
}
}
void Application::mtpUnpause() {
QTimer::singleShot(1, this, SLOT(doMtpUnpause()));
}
void Application::doMtpUnpause() {
MTP::unpause();
}
void Application::selfPhotoCleared(const MTPUserProfilePhoto &result) {
if (!App::self()) return;
App::self()->setPhoto(result);

View file

@ -55,6 +55,7 @@ public:
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
int32 updatingSize();
int32 updatingReady();
void stopUpdate();
#endif
FileUploader *uploader();
@ -64,7 +65,7 @@ public:
bool isPhotoUpdating(const PeerId &peer);
void cancelPhotoUpdate(const PeerId &peer);
void stopUpdate();
void mtpUnpause();
void selfPhotoCleared(const MTPUserProfilePhoto &result);
void chatPhotoCleared(PeerId peer, const MTPUpdates &updates);
@ -109,6 +110,8 @@ public slots:
void newInstanceConnected();
void closeApplication();
void doMtpUnpause();
void readClients();
void removeClients();

View file

@ -22,6 +22,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
#include "style.h"
#include "lang.h"
#include "application.h"
#include "window.h"
#include "dialogswidget.h"
#include "mainwidget.h"
@ -1572,6 +1573,8 @@ void DialogsWidget::dialogsToUp() {
}
void DialogsWidget::animShow(const QPixmap &bgAnimCache) {
MTP::pause();
_bgAnimCache = bgAnimCache;
_animCache = myGrab(this, rect());
_scroll.hide();
@ -1600,6 +1603,8 @@ bool DialogsWidget::animStep(float64 ms) {
_filter.show();
onFilterUpdate(true);
activate();
if (App::app()) App::app()->mtpUnpause();
} else {
a_bgCoord.update(dt1, st::introHideFunc);
a_bgAlpha.update(dt1, st::introAlphaHideFunc);

View file

@ -186,6 +186,7 @@ void FlatTextarea::paintEvent(QPaintEvent *e) {
p.setPen(a_phColor.current());
p.drawText(phRect, _ph, QTextOption(_st.phAlign));
p.restore();
p.setOpacity(1);
}
QTextEdit::paintEvent(e);
}

View file

@ -22,6 +22,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
#include "style.h"
#include "lang.h"
#include "application.h"
#include "boxes/confirmbox.h"
#include "historywidget.h"
#include "gui/filedialog.h"
@ -3992,6 +3993,8 @@ HistoryItem *HistoryWidget::atTopImportantMsg(int32 &bottomUnderScrollTop) const
}
void HistoryWidget::animShow(const QPixmap &bgAnimCache, const QPixmap &bgAnimTopBarCache, bool back) {
MTP::pause();
_bgAnimCache = bgAnimCache;
_bgAnimTopBarCache = bgAnimTopBarCache;
_animCache = myGrab(this, rect());
@ -4042,6 +4045,8 @@ bool HistoryWidget::showStep(float64 ms) {
App::main()->topBar()->stopAnim();
App::main()->topBar()->enableShadow();
doneShow();
if (App::app()) App::app()->mtpUnpause();
} else {
a_bgCoord.update(dt1, st::introHideFunc);
a_bgAlpha.update(dt1, st::introAlphaHideFunc);

View file

@ -145,6 +145,8 @@ bool IntroWidget::createNext() {
}
void IntroWidget::prepareMove() {
MTP::pause();
if (cacheForHide.isNull() || cacheForHideInd != current) makeHideCache();
stages[current + moving]->prepareShow();
@ -198,6 +200,8 @@ void IntroWidget::makeShowCache(int stage) {
}
void IntroWidget::animShow(const QPixmap &bgAnimCache, bool back) {
MTP::pause();
_bgAnimCache = bgAnimCache;
anim::stop(this);
@ -245,6 +249,7 @@ bool IntroWidget::animStep(float64 ms) {
_back.setOpacity(1);
_back.show();
}
if (App::app()) App::app()->mtpUnpause();
} else {
a_bgCoord.update(dt1, st::introHideFunc);
a_bgAlpha.update(dt1, st::introAlphaHideFunc);
@ -265,6 +270,7 @@ bool IntroWidget::animStep(float64 ms) {
if (!stages[current]->hasBack()) {
_back.hide();
}
if (App::app()) App::app()->mtpUnpause();
} else {
xCoordShow.update(dt2, st::introShowFunc);
cAlphaShow.update(dt2, st::introAlphaShowFunc);

View file

@ -2705,6 +2705,8 @@ void MainWidget::historyCleared(History *hist) {
}
void MainWidget::animShow(const QPixmap &bgAnimCache, bool back) {
MTP::pause();
_bgAnimCache = bgAnimCache;
anim::stop(this);
@ -2737,6 +2739,8 @@ bool MainWidget::animStep(float64 ms) {
anim::stop(this);
showAll();
activate();
if (App::app()) App::app()->mtpUnpause();
} else {
a_bgCoord.update(dt1, st::introHideFunc);
a_bgAlpha.update(dt1, st::introAlphaHideFunc);

View file

@ -352,6 +352,8 @@ namespace {
return false;
}
bool _paused = false;
}
namespace _mtp_internal {
@ -371,6 +373,10 @@ namespace _mtp_internal {
sessions.insert(dcWithShift, result);
return result;
}
bool paused() {
return _paused;
}
void registerRequest(mtpRequestId requestId, int32 dcWithShift) {
{
@ -643,6 +649,7 @@ namespace MTP {
(*i)->restart();
}
}
void restart(int32 dcMask) {
if (!_started) return;
@ -654,6 +661,19 @@ namespace MTP {
}
}
void pause() {
if (!_started) return;
_paused = true;
}
void unpause() {
if (!_started) return;
_paused = false;
for (Sessions::const_iterator i = sessions.cbegin(), e = sessions.cend(); i != e; ++i) {
(*i)->unpaused();
}
}
void configure(int32 dc, int32 user) {
if (_started) return;
mtpSetDC(dc);

View file

@ -26,6 +26,8 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
namespace _mtp_internal {
MTProtoSessionPtr getSession(int32 dc = 0); // 0 - current set dc
bool paused();
void registerRequest(mtpRequestId requestId, int32 dc);
void unregisterRequest(mtpRequestId requestId);
@ -86,6 +88,9 @@ namespace MTP {
void restart();
void restart(int32 dcMask);
void pause();
void unpause();
void configure(int32 dc, int32 user);
void setdc(int32 dc, bool fromZeroOnly = false);

View file

@ -66,7 +66,15 @@ void MTPSessionData::clear() {
}
MTProtoSession::MTProtoSession() : _killed(false), data(this), dcWithShift(0), dc(0), msSendCall(0), msWait(0), _ping(false) {
MTProtoSession::MTProtoSession() : QObject()
, _killed(false)
, _needToReceive(false)
, data(this)
, dcWithShift(0)
, dc(0)
, msSendCall(0)
, msWait(0)
, _ping(false) {
}
void MTProtoSession::start(int32 dcenter) {
@ -144,6 +152,13 @@ void MTProtoSession::kill() {
DEBUG_LOG(("Session Info: marked session dcWithShift %1 as killed").arg(dcWithShift));
}
void MTProtoSession::unpaused() {
if (_needToReceive) {
_needToReceive = false;
tryToReceive();
}
}
void MTProtoSession::sendAnything(quint64 msCanWait) {
if (_killed) {
DEBUG_LOG(("Session Error: can't send anything in a killed session"));
@ -492,6 +507,10 @@ int32 MTProtoSession::getDcWithShift() const {
}
void MTProtoSession::tryToReceive() {
if (_mtp_internal::paused()) {
_needToReceive = true;
return;
}
int32 cnt = 0;
while (true) {
mtpRequestId requestId;

View file

@ -229,6 +229,8 @@ public:
void stop();
void kill();
void unpaused();
int32 getDcWithShift() const;
~MTProtoSession();
@ -281,6 +283,7 @@ private:
MTProtoConnections connections;
bool _killed;
bool _needToReceive;
MTPSessionData data;

View file

@ -2776,9 +2776,13 @@ void OverviewWidget::fastShow(bool back, int32 lastScrollTop) {
show();
_inner.activate();
doneShow();
if (App::app()) App::app()->mtpUnpause();
}
void OverviewWidget::animShow(const QPixmap &bgAnimCache, const QPixmap &bgAnimTopBarCache, bool back, int32 lastScrollTop) {
MTP::pause();
stopGif();
_bgAnimCache = bgAnimCache;
_bgAnimTopBarCache = bgAnimTopBarCache;
@ -2814,6 +2818,8 @@ bool OverviewWidget::animStep(float64 ms) {
_bgAnimCache = _animCache = _animTopBarCache = _bgAnimTopBarCache = QPixmap();
App::main()->topBar()->stopAnim();
doneShow();
if (App::app()) App::app()->mtpUnpause();
} else {
a_bgCoord.update(dt1, st::introHideFunc);
a_bgAlpha.update(dt1, st::introAlphaHideFunc);

View file

@ -112,6 +112,8 @@ void PasscodeWidget::onChanged() {
}
void PasscodeWidget::animShow(const QPixmap &bgAnimCache, bool back) {
MTP::pause();
_bgAnimCache = bgAnimCache;
anim::stop(this);
@ -143,6 +145,8 @@ bool PasscodeWidget::animStep(float64 ms) {
showAll();
if (App::wnd()) App::wnd()->setInnerFocus();
if (App::app()) App::app()->mtpUnpause();
} else {
a_bgCoord.update(dt1, st::introHideFunc);
a_bgAlpha.update(dt1, st::introAlphaHideFunc);

View file

@ -1616,6 +1616,8 @@ int32 ProfileWidget::lastScrollTop() const {
}
void ProfileWidget::animShow(const QPixmap &bgAnimCache, const QPixmap &bgAnimTopBarCache, bool back, int32 lastScrollTop) {
MTP::pause();
stopGif();
_bgAnimCache = bgAnimCache;
_bgAnimTopBarCache = bgAnimTopBarCache;
@ -1651,6 +1653,8 @@ bool ProfileWidget::animStep(float64 ms) {
_scroll.show();
_inner.start();
activate();
if (App::app()) App::app()->mtpUnpause();
} else {
a_bgCoord.update(dt1, st::introHideFunc);
a_bgAlpha.update(dt1, st::introAlphaHideFunc);

View file

@ -1768,6 +1768,8 @@ void SettingsWidget::onParentResize(const QSize &newSize) {
}
void SettingsWidget::animShow(const QPixmap &bgAnimCache, bool back) {
MTP::pause();
_bgAnimCache = bgAnimCache;
anim::stop(this);
@ -1799,6 +1801,8 @@ bool SettingsWidget::animStep(float64 ms) {
showAll();
_inner.setFocus();
if (App::app()) App::app()->mtpUnpause();
} else {
a_bgCoord.update(dt1, st::introHideFunc);
a_bgAlpha.update(dt1, st::introAlphaHideFunc);