This commit is contained in:
John Preston 2015-04-16 18:00:43 +03:00
commit 9b3767e77c
15 changed files with 79 additions and 18 deletions

View File

@ -1812,16 +1812,22 @@ namespace App {
if (Local::readBackground()) return; if (Local::readBackground()) return;
QImage img(p); QImage img(p);
bool remove = false;
if (p.isNull()) { if (p.isNull()) {
img.load(st::msgBG); img.load(st::msgBG);
id = 0; id = 0;
remove = true;
} }
if (img.format() != QImage::Format_ARGB32 && img.format() != QImage::Format_ARGB32_Premultiplied && img.format() != QImage::Format_RGB32) { if (img.format() != QImage::Format_ARGB32 && img.format() != QImage::Format_ARGB32_Premultiplied && img.format() != QImage::Format_RGB32) {
img = img.convertToFormat(QImage::Format_RGB32); img = img.convertToFormat(QImage::Format_RGB32);
} }
img.setDevicePixelRatio(cRetinaFactor()); img.setDevicePixelRatio(cRetinaFactor());
if (!nowrite) Local::writeBackground(id, img); if (remove) {
Local::writeBackground(0, QImage());
} else if (!nowrite) {
Local::writeBackground(id, img);
}
delete cChatBackground(); delete cChatBackground();
cSetChatBackground(new QPixmap(QPixmap::fromImage(img, Qt::ColorOnly))); cSetChatBackground(new QPixmap(QPixmap::fromImage(img, Qt::ColorOnly)));

View File

@ -60,6 +60,9 @@ namespace {
App::wnd()->minimizeToTray(); App::wnd()->minimizeToTray();
return true; return true;
} }
} else if (ev->key() == Qt::Key_M && (ev->modifiers() & (Qt::MetaModifier | Qt::ControlModifier))) {
App::wnd()->setWindowState(Qt::WindowMinimized);
return true;
} }
} }
return QObject::eventFilter(o, e); return QObject::eventFilter(o, e);

View File

@ -78,7 +78,7 @@ void BackgroundInner::gotWallpapers(const MTPVector<MTPWallPaper> &result) {
} }
} }
if (thumb && full && full->type() != mtpc_photoSizeEmpty) { if (thumb && full && full->type() != mtpc_photoSizeEmpty) {
wallpapers.push_back(App::WallPaper(d.vid.v, App::image(*thumb), App::image(*full))); wallpapers.push_back(App::WallPaper(d.vid.v ? d.vid.v : INT_MAX, App::image(*thumb), App::image(*full)));
} }
} break; } break;

View File

@ -279,8 +279,8 @@ enum {
UploadRequestInterval = 500, // one part each half second, if not uploaded faster UploadRequestInterval = 500, // one part each half second, if not uploaded faster
MaxPhotosInMemory = 50, // try to clear some memory after 50 photos are created MaxPhotosInMemory = 50, // try to clear some memory after 50 photos are created
NoUpdatesTimeout = 180 * 1000, // if nothing is received in 3 min we getDifference NoUpdatesTimeout = 60 * 1000, // if nothing is received in 1 min we ping
NoUpdatesAfterSleepTimeout = 60 * 1000, // if nothing is received in 1 min when was a sleepmode we getDifference NoUpdatesAfterSleepTimeout = 60 * 1000, // if nothing is received in 1 min when was a sleepmode we ping
WaitForSkippedTimeout = 1000, // 1s wait for skipped seq or pts in updates WaitForSkippedTimeout = 1000, // 1s wait for skipped seq or pts in updates
MemoryForImageCache = 64 * 1024 * 1024, // after 64mb of unpacked images we try to clear some memory MemoryForImageCache = 64 * 1024 * 1024, // after 64mb of unpacked images we try to clear some memory

View File

@ -1783,7 +1783,7 @@ void HistoryPhoto::updateFrom(const MTPMessageMedia &media) {
case mtpc_photoCachedSize: { case mtpc_photoCachedSize: {
const string &s(i->c_photoCachedSize().vtype.c_string().v); const string &s(i->c_photoCachedSize().vtype.c_string().v);
loc = &i->c_photoSize().vlocation; loc = &i->c_photoCachedSize().vlocation;
if (s.size()) size = s[0]; if (s.size()) size = s[0];
} break; } break;
} }

View File

@ -2178,6 +2178,15 @@ namespace Local {
void writeBackground(int32 id, const QImage &img) { void writeBackground(int32 id, const QImage &img) {
if (!_working()) return; if (!_working()) return;
if (img.isNull()) {
if (_backgroundKey) {
clearKey(_backgroundKey);
_backgroundKey = 0;
_mapChanged = true;
}
_writeMap();
return;
}
QByteArray png; QByteArray png;
{ {
QBuffer buf(&png); QBuffer buf(&png);

View File

@ -360,7 +360,7 @@ _failDifferenceTimeout(1), _lastUpdateTime(0), _cachedX(0), _cachedY(0), _backgr
connect(&dialogs, SIGNAL(cancelled()), this, SLOT(dialogsCancelled())); connect(&dialogs, SIGNAL(cancelled()), this, SLOT(dialogsCancelled()));
connect(&history, SIGNAL(cancelled()), &dialogs, SLOT(activate())); connect(&history, SIGNAL(cancelled()), &dialogs, SLOT(activate()));
connect(this, SIGNAL(peerPhotoChanged(PeerData*)), this, SIGNAL(dialogsUpdated())); connect(this, SIGNAL(peerPhotoChanged(PeerData*)), this, SIGNAL(dialogsUpdated()));
connect(&noUpdatesTimer, SIGNAL(timeout()), this, SLOT(getDifference())); connect(&noUpdatesTimer, SIGNAL(timeout()), this, SLOT(mtpPing()));
connect(&_onlineTimer, SIGNAL(timeout()), this, SLOT(updateOnline())); connect(&_onlineTimer, SIGNAL(timeout()), this, SLOT(updateOnline()));
connect(&_onlineUpdater, SIGNAL(timeout()), this, SLOT(updateOnlineDisplay())); connect(&_onlineUpdater, SIGNAL(timeout()), this, SLOT(updateOnlineDisplay()));
connect(&_idleFinishTimer, SIGNAL(timeout()), this, SLOT(checkIdleFinish())); connect(&_idleFinishTimer, SIGNAL(timeout()), this, SLOT(checkIdleFinish()));
@ -1195,7 +1195,8 @@ void MainWidget::peerUsernameChanged(PeerData *peer) {
void MainWidget::checkLastUpdate(bool afterSleep) { void MainWidget::checkLastUpdate(bool afterSleep) {
uint64 n = getms(true); uint64 n = getms(true);
if (_lastUpdateTime && n > _lastUpdateTime + (afterSleep ? NoUpdatesAfterSleepTimeout : NoUpdatesTimeout)) { if (_lastUpdateTime && n > _lastUpdateTime + (afterSleep ? NoUpdatesAfterSleepTimeout : NoUpdatesTimeout)) {
getDifference(); _lastUpdateTime = n;
MTP::ping();
} }
} }
@ -1591,7 +1592,7 @@ void MainWidget::checkChatBackground() {
if (_background->full->isNull()) { if (_background->full->isNull()) {
App::initBackground(); App::initBackground();
} else { } else {
App::initBackground(_background->id, _background->full->pix().toImage()); App::initBackground(_background->id, _background->id ? _background->full->pix().toImage() : QImage());
} }
delete _background; delete _background;
_background = 0; _background = 0;
@ -2398,6 +2399,10 @@ void MainWidget::getDifference() {
MTP::send(MTPupdates_GetDifference(MTP_int(updGoodPts), MTP_int(updDate), MTP_int(updQts)), rpcDone(&MainWidget::gotDifference), rpcFail(&MainWidget::failDifference)); MTP::send(MTPupdates_GetDifference(MTP_int(updGoodPts), MTP_int(updDate), MTP_int(updQts)), rpcDone(&MainWidget::gotDifference), rpcFail(&MainWidget::failDifference));
} }
void MainWidget::mtpPing() {
MTP::ping();
}
void MainWidget::start(const MTPUser &user) { void MainWidget::start(const MTPUser &user) {
int32 uid = user.c_userSelf().vid.v; int32 uid = user.c_userSelf().vid.v;
if (MTP::authedId() != uid) { if (MTP::authedId() != uid) {
@ -2805,6 +2810,7 @@ void MainWidget::handleUpdates(const MTPUpdates &updates) {
case mtpc_updateShortMessage: { case mtpc_updateShortMessage: {
const MTPDupdateShortMessage &d(updates.c_updateShortMessage()); const MTPDupdateShortMessage &d(updates.c_updateShortMessage());
if (!App::userLoaded(d.vuser_id.v) || (d.has_fwd_from_id() && !App::userLoaded(d.vfwd_from_id.v))) { if (!App::userLoaded(d.vuser_id.v) || (d.has_fwd_from_id() && !App::userLoaded(d.vfwd_from_id.v))) {
DEBUG_LOG(("Not loaded for updateShortMessage, good getDifference!"));
return getDifference(); return getDifference();
} }
if (!updPtsUpdated(d.vpts.v, d.vpts_count.v)) { if (!updPtsUpdated(d.vpts.v, d.vpts_count.v)) {
@ -2823,6 +2829,7 @@ void MainWidget::handleUpdates(const MTPUpdates &updates) {
case mtpc_updateShortChatMessage: { case mtpc_updateShortChatMessage: {
const MTPDupdateShortChatMessage &d(updates.c_updateShortChatMessage()); const MTPDupdateShortChatMessage &d(updates.c_updateShortChatMessage());
if (!App::chatLoaded(d.vchat_id.v) || !App::userLoaded(d.vfrom_id.v) || (d.has_fwd_from_id() && !App::userLoaded(d.vfwd_from_id.v))) { if (!App::chatLoaded(d.vchat_id.v) || !App::userLoaded(d.vfrom_id.v) || (d.has_fwd_from_id() && !App::userLoaded(d.vfwd_from_id.v))) {
DEBUG_LOG(("Not loaded for updateShortMessage, good getDifference!"));
return getDifference(); return getDifference();
} }
if (!updPtsUpdated(d.vpts.v, d.vpts_count.v)) { if (!updPtsUpdated(d.vpts.v, d.vpts_count.v)) {

View File

@ -367,6 +367,7 @@ public slots:
void onParentResize(const QSize &newSize); void onParentResize(const QSize &newSize);
void getDifference(); void getDifference();
void mtpPing();
void getDifferenceForce(); void getDifferenceForce();
void updateOnline(bool gotOtherOffline = false); void updateOnline(bool gotOtherOffline = false);

View File

@ -684,6 +684,13 @@ namespace MTP {
_mtp_internal::getSession(dc); _mtp_internal::getSession(dc);
} }
void ping() {
MTProtoSessionPtr session = _mtp_internal::getSession(0);
if (!session) return;
return session->ping();
}
void cancel(mtpRequestId requestId) { void cancel(mtpRequestId requestId) {
mtpMsgId msgId = 0; mtpMsgId msgId = 0;
requestsDelays.remove(requestId); requestsDelays.remove(requestId);

View File

@ -101,6 +101,7 @@ namespace MTP {
inline mtpRequestId send(const TRequest &request, RPCDoneHandlerPtr onDone, RPCFailHandlerPtr onFail = RPCFailHandlerPtr(), int32 dc = 0, uint64 msCanWait = 0, mtpRequestId after = 0) { inline mtpRequestId send(const TRequest &request, RPCDoneHandlerPtr onDone, RPCFailHandlerPtr onFail = RPCFailHandlerPtr(), int32 dc = 0, uint64 msCanWait = 0, mtpRequestId after = 0) {
return send(request, RPCResponseHandler(onDone, onFail), dc, msCanWait, after); return send(request, RPCResponseHandler(onDone, onFail), dc, msCanWait, after);
} }
void ping();
void cancel(mtpRequestId req); void cancel(mtpRequestId req);
void killSession(int32 dc); void killSession(int32 dc);
void stopSession(int32 dc); void stopSession(int32 dc);

View File

@ -1096,7 +1096,7 @@ MTProtoConnectionPrivate::MTProtoConnectionPrivate(QThread *thread, MTProtoConne
, firstSentAt(-1) , firstSentAt(-1)
, _pingId(0) , _pingId(0)
, _pingIdToSend(0) , _pingIdToSend(0)
, _pingSent(0) , _pingSendAt(0)
, _pingMsgId(0) , _pingMsgId(0)
, restarted(false) , restarted(false)
, keyId(0) , keyId(0)
@ -1137,6 +1137,7 @@ MTProtoConnectionPrivate::MTProtoConnectionPrivate(QThread *thread, MTProtoConne
connect(this, SIGNAL(needToReceive()), sessionData->owner(), SLOT(tryToReceive()), Qt::QueuedConnection); connect(this, SIGNAL(needToReceive()), sessionData->owner(), SLOT(tryToReceive()), Qt::QueuedConnection);
connect(this, SIGNAL(stateChanged(qint32)), sessionData->owner(), SLOT(onConnectionStateChange(qint32)), Qt::QueuedConnection); connect(this, SIGNAL(stateChanged(qint32)), sessionData->owner(), SLOT(onConnectionStateChange(qint32)), Qt::QueuedConnection);
connect(sessionData->owner(), SIGNAL(needToSend()), this, SLOT(tryToSend()), Qt::QueuedConnection); connect(sessionData->owner(), SIGNAL(needToSend()), this, SLOT(tryToSend()), Qt::QueuedConnection);
connect(sessionData->owner(), SIGNAL(needToPing()), this, SLOT(onPingSendForce()), Qt::QueuedConnection);
connect(this, SIGNAL(sessionResetDone()), sessionData->owner(), SLOT(onResetDone()), Qt::QueuedConnection); connect(this, SIGNAL(sessionResetDone()), sessionData->owner(), SLOT(onResetDone()), Qt::QueuedConnection);
static bool _registered = false; static bool _registered = false;
@ -1425,7 +1426,7 @@ void MTProtoConnectionPrivate::tryToSend() {
bool prependOnly = (state != MTProtoConnection::Connected); bool prependOnly = (state != MTProtoConnection::Connected);
mtpRequest pingRequest; mtpRequest pingRequest;
if (dc < _mtp_internal::dcShift) { // main session if (dc < _mtp_internal::dcShift) { // main session
if (!prependOnly && !_pingIdToSend && !_pingId && _pingSent + (MTPPingSendAfterAuto * 1000ULL) <= getms(true)) { if (!prependOnly && !_pingIdToSend && !_pingId && _pingSendAt <= getms(true)) {
_pingIdToSend = MTP::nonce<mtpPingId>(); _pingIdToSend = MTP::nonce<mtpPingId>();
} }
} }
@ -1444,7 +1445,8 @@ void MTProtoConnectionPrivate::tryToSend() {
DEBUG_LOG(("MTP Info: sending ping_delay_disconnect, ping_id: %1").arg(_pingIdToSend)); DEBUG_LOG(("MTP Info: sending ping_delay_disconnect, ping_id: %1").arg(_pingIdToSend));
} }
_pingSent = pingRequest->msDate = getms(true); // > 0 - can send without container pingRequest->msDate = getms(true); // > 0 - can send without container
_pingSendAt = pingRequest->msDate + (MTPPingSendAfterAuto * 1000ULL);
pingRequest->requestId = 0; // dont add to haveSent / wereAcked maps pingRequest->requestId = 0; // dont add to haveSent / wereAcked maps
if (dc < _mtp_internal::dcShift && !prependOnly) { // main session if (dc < _mtp_internal::dcShift && !prependOnly) { // main session
@ -1733,7 +1735,7 @@ void MTProtoConnectionPrivate::socketStart(bool afterConfig) {
return; return;
} }
setState(MTProtoConnection::Connecting); setState(MTProtoConnection::Connecting);
_pingId = _pingMsgId = _pingIdToSend = _pingSent = 0; _pingId = _pingMsgId = _pingIdToSend = _pingSendAt = 0;
_pingSender.stop(); _pingSender.stop();
const mtpDcOption *dcOption = 0; const mtpDcOption *dcOption = 0;
@ -1840,17 +1842,25 @@ void MTProtoConnectionPrivate::onOldConnection() {
void MTProtoConnectionPrivate::onPingSender() { void MTProtoConnectionPrivate::onPingSender() {
if (_pingId) { if (_pingId) {
if (_pingSent + (MTPPingSendAfter - 1) * 1000 < getms(true)) { if (_pingSendAt + (MTPPingSendAfter - MTPPingSendAfterAuto - 1) * 1000ULL < getms(true)) {
LOG(("Could not send ping for MTPPingSendAfter seconds, restarting..")); LOG(("Could not send ping for MTPPingSendAfter seconds, restarting.."));
return restart(); return restart();
} else { } else {
_pingSender.start(_pingSent + (MTPPingSendAfter * 1000) - getms(true)); _pingSender.start(_pingSendAt + (MTPPingSendAfter - MTPPingSendAfterAuto) * 1000ULL - getms(true));
} }
} else { } else {
emit needToSendAsync(); emit needToSendAsync();
} }
} }
void MTProtoConnectionPrivate::onPingSendForce() {
if (!_pingId) {
_pingSendAt = 0;
DEBUG_LOG(("Will send ping!"));
tryToSend();
}
}
void MTProtoConnectionPrivate::onBadConnection() { void MTProtoConnectionPrivate::onBadConnection() {
if (cConnectionType() != dbictAuto && cConnectionType() != dbictTcpProxy) { if (cConnectionType() != dbictAuto && cConnectionType() != dbictTcpProxy) {
return; return;

View File

@ -341,6 +341,7 @@ public slots:
void restart(bool maybeBadKey = false); void restart(bool maybeBadKey = false);
void onPingSender(); void onPingSender();
void onPingSendForce();
void onBadConnection(); void onBadConnection();
void onOldConnection(); void onOldConnection();
void onSentSome(uint64 size); void onSentSome(uint64 size);
@ -416,7 +417,7 @@ private:
void requestsAcked(const QVector<MTPlong> &ids, bool byResponse = false); void requestsAcked(const QVector<MTPlong> &ids, bool byResponse = false);
mtpPingId _pingId, _pingIdToSend; mtpPingId _pingId, _pingIdToSend;
uint64 _pingSent; uint64 _pingSendAt;
mtpMsgId _pingMsgId; mtpMsgId _pingMsgId;
SingleTimer _pingSender; SingleTimer _pingSender;

View File

@ -63,7 +63,7 @@ void MTPSessionData::clear() {
} }
MTProtoSession::MTProtoSession() : data(this), dcId(0), dc(0), msSendCall(0), msWait(0) { MTProtoSession::MTProtoSession() : data(this), dcId(0), dc(0), msSendCall(0), msWait(0), _ping(false) {
} }
void MTProtoSession::start(int32 dcenter) { void MTProtoSession::start(int32 dcenter) {
@ -171,7 +171,12 @@ void MTProtoSession::needToResumeAndSend() {
} }
} }
} }
emit needToSend(); if (_ping) {
_ping = false;
emit needToPing();
} else {
emit needToSend();
}
} }
void MTProtoSession::sendPong(quint64 msgId, quint64 pingId) { void MTProtoSession::sendPong(quint64 msgId, quint64 pingId) {
@ -272,6 +277,11 @@ void MTProtoSession::cancel(mtpRequestId requestId, mtpMsgId msgId) {
} }
} }
void MTProtoSession::ping() {
_ping = true;
sendAnything(0);
}
int32 MTProtoSession::requestState(mtpRequestId requestId) const { int32 MTProtoSession::requestState(mtpRequestId requestId) const {
MTProtoConnections::const_iterator j = connections.cbegin(), e = connections.cend(); MTProtoConnections::const_iterator j = connections.cbegin(), e = connections.cend();
int32 result = MTP::RequestSent; int32 result = MTP::RequestSent;

View File

@ -236,6 +236,7 @@ public:
template <typename TRequest> template <typename TRequest>
mtpRequestId send(const TRequest &request, RPCResponseHandler callbacks = RPCResponseHandler(), uint64 msCanWait = 0, bool needsLayer = false, bool toMainDC = false, mtpRequestId after = 0); // send mtp request mtpRequestId send(const TRequest &request, RPCResponseHandler callbacks = RPCResponseHandler(), uint64 msCanWait = 0, bool needsLayer = false, bool toMainDC = false, mtpRequestId after = 0); // send mtp request
void ping();
void cancel(mtpRequestId requestId, mtpMsgId msgId); void cancel(mtpRequestId requestId, mtpMsgId msgId);
int32 requestState(mtpRequestId requestId) const; int32 requestState(mtpRequestId requestId) const;
int32 getState() const; int32 getState() const;
@ -247,6 +248,7 @@ signals:
void authKeyCreated(); void authKeyCreated();
void needToSend(); void needToSend();
void needToPing();
void needToRestart(); void needToRestart();
public slots: public slots:
@ -281,6 +283,8 @@ private:
uint64 msSendCall, msWait; uint64 msSendCall, msWait;
bool _ping;
QTimer timeouter; QTimer timeouter;
SingleTimer sender; SingleTimer sender;

View File

@ -1335,7 +1335,7 @@
6DB9C3763D02B1415CD9D565 /* Project object */ = { 6DB9C3763D02B1415CD9D565 /* Project object */ = {
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastUpgradeCheck = 0610; LastUpgradeCheck = 0630;
TargetAttributes = { TargetAttributes = {
7CCA95B9FCAD34D929431AD6 = { 7CCA95B9FCAD34D929431AD6 = {
DevelopmentTeam = 63FLR8MQA9; DevelopmentTeam = 63FLR8MQA9;
@ -1735,6 +1735,7 @@
FRAMEWORK_SEARCH_PATHS = ""; FRAMEWORK_SEARCH_PATHS = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = YES; GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
GCC_LINK_WITH_DYNAMIC_LIBRARIES = NO; GCC_LINK_WITH_DYNAMIC_LIBRARIES = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = fast; GCC_OPTIMIZATION_LEVEL = fast;
GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = SourceFiles/stdafx.h; GCC_PREFIX_HEADER = SourceFiles/stdafx.h;
@ -1876,6 +1877,7 @@
FRAMEWORK_SEARCH_PATHS = ""; FRAMEWORK_SEARCH_PATHS = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = YES; GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
GCC_LINK_WITH_DYNAMIC_LIBRARIES = NO; GCC_LINK_WITH_DYNAMIC_LIBRARIES = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = SourceFiles/stdafx.h; GCC_PREFIX_HEADER = SourceFiles/stdafx.h;