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) { void Application::selfPhotoCleared(const MTPUserProfilePhoto &result) {
if (!App::self()) return; if (!App::self()) return;
App::self()->setPhoto(result); App::self()->setPhoto(result);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -352,6 +352,8 @@ namespace {
return false; return false;
} }
bool _paused = false;
} }
namespace _mtp_internal { namespace _mtp_internal {
@ -371,6 +373,10 @@ namespace _mtp_internal {
sessions.insert(dcWithShift, result); sessions.insert(dcWithShift, result);
return result; return result;
} }
bool paused() {
return _paused;
}
void registerRequest(mtpRequestId requestId, int32 dcWithShift) { void registerRequest(mtpRequestId requestId, int32 dcWithShift) {
{ {
@ -643,6 +649,7 @@ namespace MTP {
(*i)->restart(); (*i)->restart();
} }
} }
void restart(int32 dcMask) { void restart(int32 dcMask) {
if (!_started) return; 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) { void configure(int32 dc, int32 user) {
if (_started) return; if (_started) return;
mtpSetDC(dc); mtpSetDC(dc);

View File

@ -26,6 +26,8 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
namespace _mtp_internal { namespace _mtp_internal {
MTProtoSessionPtr getSession(int32 dc = 0); // 0 - current set dc MTProtoSessionPtr getSession(int32 dc = 0); // 0 - current set dc
bool paused();
void registerRequest(mtpRequestId requestId, int32 dc); void registerRequest(mtpRequestId requestId, int32 dc);
void unregisterRequest(mtpRequestId requestId); void unregisterRequest(mtpRequestId requestId);
@ -86,6 +88,9 @@ namespace MTP {
void restart(); void restart();
void restart(int32 dcMask); void restart(int32 dcMask);
void pause();
void unpause();
void configure(int32 dc, int32 user); void configure(int32 dc, int32 user);
void setdc(int32 dc, bool fromZeroOnly = false); 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) { void MTProtoSession::start(int32 dcenter) {
@ -144,6 +152,13 @@ void MTProtoSession::kill() {
DEBUG_LOG(("Session Info: marked session dcWithShift %1 as killed").arg(dcWithShift)); 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) { void MTProtoSession::sendAnything(quint64 msCanWait) {
if (_killed) { if (_killed) {
DEBUG_LOG(("Session Error: can't send anything in a killed session")); DEBUG_LOG(("Session Error: can't send anything in a killed session"));
@ -492,6 +507,10 @@ int32 MTProtoSession::getDcWithShift() const {
} }
void MTProtoSession::tryToReceive() { void MTProtoSession::tryToReceive() {
if (_mtp_internal::paused()) {
_needToReceive = true;
return;
}
int32 cnt = 0; int32 cnt = 0;
while (true) { while (true) {
mtpRequestId requestId; mtpRequestId requestId;

View File

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

View File

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

View File

@ -112,6 +112,8 @@ void PasscodeWidget::onChanged() {
} }
void PasscodeWidget::animShow(const QPixmap &bgAnimCache, bool back) { void PasscodeWidget::animShow(const QPixmap &bgAnimCache, bool back) {
MTP::pause();
_bgAnimCache = bgAnimCache; _bgAnimCache = bgAnimCache;
anim::stop(this); anim::stop(this);
@ -143,6 +145,8 @@ bool PasscodeWidget::animStep(float64 ms) {
showAll(); showAll();
if (App::wnd()) App::wnd()->setInnerFocus(); if (App::wnd()) App::wnd()->setInnerFocus();
if (App::app()) App::app()->mtpUnpause();
} else { } else {
a_bgCoord.update(dt1, st::introHideFunc); a_bgCoord.update(dt1, st::introHideFunc);
a_bgAlpha.update(dt1, st::introAlphaHideFunc); 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) { void ProfileWidget::animShow(const QPixmap &bgAnimCache, const QPixmap &bgAnimTopBarCache, bool back, int32 lastScrollTop) {
MTP::pause();
stopGif(); stopGif();
_bgAnimCache = bgAnimCache; _bgAnimCache = bgAnimCache;
_bgAnimTopBarCache = bgAnimTopBarCache; _bgAnimTopBarCache = bgAnimTopBarCache;
@ -1651,6 +1653,8 @@ bool ProfileWidget::animStep(float64 ms) {
_scroll.show(); _scroll.show();
_inner.start(); _inner.start();
activate(); activate();
if (App::app()) App::app()->mtpUnpause();
} else { } else {
a_bgCoord.update(dt1, st::introHideFunc); a_bgCoord.update(dt1, st::introHideFunc);
a_bgAlpha.update(dt1, st::introAlphaHideFunc); 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) { void SettingsWidget::animShow(const QPixmap &bgAnimCache, bool back) {
MTP::pause();
_bgAnimCache = bgAnimCache; _bgAnimCache = bgAnimCache;
anim::stop(this); anim::stop(this);
@ -1799,6 +1801,8 @@ bool SettingsWidget::animStep(float64 ms) {
showAll(); showAll();
_inner.setFocus(); _inner.setFocus();
if (App::app()) App::app()->mtpUnpause();
} else { } else {
a_bgCoord.update(dt1, st::introHideFunc); a_bgCoord.update(dt1, st::introHideFunc);
a_bgAlpha.update(dt1, st::introAlphaHideFunc); a_bgAlpha.update(dt1, st::introAlphaHideFunc);