mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-19 01:48:09 +00:00
Replace SingleTimer with base::Timer.
This commit is contained in:
parent
61b9a32504
commit
314e30272b
Telegram
SourceFiles
apiwrap.happ.cppapplication.cppapplication.h
boxes
config.hcore
data
dialogs
facades.hhistory
info/profile
mainwidget.cppmainwidget.hmainwindow.cppmainwindow.hmediaview.cppmessenger.cppmessenger.hmtproto
passport
platform
settings
storage
ui
window
gyp
@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "base/timer.h"
|
||||
#include "base/flat_map.h"
|
||||
#include "base/flat_set.h"
|
||||
#include "core/single_timer.h"
|
||||
#include "mtproto/sender.h"
|
||||
#include "chat_helpers/stickers.h"
|
||||
#include "data/data_messages.h"
|
||||
|
@ -810,7 +810,7 @@ namespace App {
|
||||
setLaunchState(QuitRequested);
|
||||
|
||||
if (auto window = App::wnd()) {
|
||||
if (!Sandbox::isSavingSession()) {
|
||||
if (!Core::App().isSavingSession()) {
|
||||
window->hide();
|
||||
}
|
||||
}
|
||||
|
@ -510,39 +510,8 @@ void Application::closeApplication() {
|
||||
_updateChecker = nullptr;
|
||||
}
|
||||
|
||||
inline Application *application() {
|
||||
return qobject_cast<Application*>(QApplication::instance());
|
||||
}
|
||||
|
||||
namespace Sandbox {
|
||||
|
||||
QRect availableGeometry() {
|
||||
if (auto a = application()) {
|
||||
return a->desktop()->availableGeometry();
|
||||
}
|
||||
return QDesktopWidget().availableGeometry();
|
||||
}
|
||||
|
||||
QRect screenGeometry(const QPoint &p) {
|
||||
if (auto a = application()) {
|
||||
return a->desktop()->screenGeometry(p);
|
||||
}
|
||||
return QDesktopWidget().screenGeometry(p);
|
||||
}
|
||||
|
||||
void setActiveWindow(QWidget *window) {
|
||||
if (auto a = application()) {
|
||||
a->setActiveWindow(window);
|
||||
}
|
||||
}
|
||||
|
||||
bool isSavingSession() {
|
||||
if (auto a = application()) {
|
||||
return a->isSavingSession();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void execExternal(const QString &cmd) {
|
||||
DEBUG_LOG(("Application Info: executing external command '%1'").arg(cmd));
|
||||
if (cmd == "show") {
|
||||
@ -554,23 +523,7 @@ void execExternal(const QString &cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
void adjustSingleTimers() {
|
||||
if (auto a = application()) {
|
||||
a->adjustSingleTimers();
|
||||
}
|
||||
base::Timer::Adjust();
|
||||
base::ConcurrentTimerEnvironment::Adjust();
|
||||
}
|
||||
|
||||
void connect(const char *signal, QObject *object, const char *method) {
|
||||
if (auto a = application()) {
|
||||
a->connect(a, signal, object, method);
|
||||
}
|
||||
}
|
||||
|
||||
void launch() {
|
||||
Assert(application() != 0);
|
||||
|
||||
const auto dpi = Application::primaryScreen()->logicalDotsPerInch();
|
||||
LOG(("Primary screen DPI: %1").arg(dpi));
|
||||
if (dpi <= 108) {
|
||||
@ -587,7 +540,7 @@ void launch() {
|
||||
cSetScreenScale(300); // 300%: 288 DPI (264-inf)
|
||||
}
|
||||
|
||||
auto devicePixelRatio = application()->devicePixelRatio();
|
||||
auto devicePixelRatio = Core::App().devicePixelRatio();
|
||||
if (devicePixelRatio > 1.) {
|
||||
if ((cPlatform() != dbipMac && cPlatform() != dbipMacOld) || (devicePixelRatio != 2.)) {
|
||||
LOG(("Found non-trivial Device Pixel Ratio: %1").arg(devicePixelRatio));
|
||||
@ -601,13 +554,7 @@ void launch() {
|
||||
cSetScreenScale(kInterfaceScaleDefault);
|
||||
}
|
||||
|
||||
application()->createMessenger();
|
||||
}
|
||||
|
||||
void refreshGlobalProxy() {
|
||||
if (const auto instance = application()) {
|
||||
instance->refreshGlobalProxy();
|
||||
}
|
||||
Core::App().createMessenger();
|
||||
}
|
||||
|
||||
} // namespace Sandbox
|
||||
|
@ -40,9 +40,6 @@ public:
|
||||
|
||||
~Application();
|
||||
|
||||
signals:
|
||||
void adjustSingleTimers();
|
||||
|
||||
// Single instance application
|
||||
public slots:
|
||||
void socketConnected();
|
||||
@ -115,19 +112,7 @@ inline Application &App() {
|
||||
|
||||
namespace Sandbox {
|
||||
|
||||
QRect availableGeometry();
|
||||
QRect screenGeometry(const QPoint &p);
|
||||
void setActiveWindow(QWidget *window);
|
||||
bool isSavingSession();
|
||||
|
||||
void execExternal(const QString &cmd);
|
||||
|
||||
void adjustSingleTimers();
|
||||
|
||||
void refreshGlobalProxy();
|
||||
|
||||
void connect(const char *signal, QObject *object, const char *method);
|
||||
|
||||
void launch();
|
||||
|
||||
} // namespace Sandbox
|
||||
|
@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "mainwidget.h"
|
||||
#include "mainwindow.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "application.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "styles/style_boxes.h"
|
||||
@ -70,7 +69,7 @@ void AboutBox::showVersionHistory() {
|
||||
}
|
||||
url = url.arg(qsl("talpha%1_%2").arg(cRealAlphaVersion()).arg(Core::countAlphaVersionSignature(cRealAlphaVersion())));
|
||||
|
||||
Application::clipboard()->setText(url);
|
||||
QApplication::clipboard()->setText(url);
|
||||
|
||||
Ui::show(Box<InformBox>("The link to the current private alpha version of Telegram Desktop was copied to the clipboard."));
|
||||
} else {
|
||||
|
@ -33,7 +33,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "mainwidget.h"
|
||||
#include "messenger.h"
|
||||
#include "apiwrap.h"
|
||||
#include "application.h"
|
||||
#include "auth_session.h"
|
||||
#include "observer_peer.h"
|
||||
#include "styles/style_boxes.h"
|
||||
@ -742,7 +741,7 @@ object_ptr<Ui::RpWidget> Controller::createInviteLinkEdit() {
|
||||
_controls.inviteLink->setContextCopyText(QString());
|
||||
_controls.inviteLink->setBreakEverywhere(true);
|
||||
_controls.inviteLink->setClickHandlerFilter([=](auto&&...) {
|
||||
Application::clipboard()->setText(inviteLinkText());
|
||||
QApplication::clipboard()->setText(inviteLinkText());
|
||||
Ui::Toast::Show(lang(lng_group_invite_copied));
|
||||
return false;
|
||||
});
|
||||
|
@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "boxes/username_box.h"
|
||||
|
||||
#include "lang/lang_keys.h"
|
||||
#include "application.h"
|
||||
#include "mainwidget.h"
|
||||
#include "mainwindow.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
@ -166,7 +165,7 @@ void UsernameBox::changed() {
|
||||
}
|
||||
|
||||
void UsernameBox::linkClick() {
|
||||
Application::clipboard()->setText(Messenger::Instance().createInternalLinkFull(getName()));
|
||||
QApplication::clipboard()->setText(Messenger::Instance().createInternalLinkFull(getName()));
|
||||
Ui::Toast::Show(lang(lng_username_copied));
|
||||
}
|
||||
|
||||
@ -180,7 +179,7 @@ bool UsernameBox::onUpdateFail(const RPCError &error) {
|
||||
|
||||
_saveRequestId = 0;
|
||||
const auto self = Auth().user();
|
||||
const auto err = error.type();
|
||||
const auto &err = error.type();
|
||||
if (err == qstr("USERNAME_NOT_MODIFIED") || _sentUsername == self->username) {
|
||||
self->setName(
|
||||
TextUtilities::SingleLine(self->firstName),
|
||||
|
@ -26,8 +26,6 @@ enum {
|
||||
|
||||
MTPKillFileSessionTimeout = 5000, // how much time without upload / download causes additional session kill
|
||||
|
||||
MTPChannelGetDifferenceLimit = 100,
|
||||
|
||||
MaxSelectedItems = 100,
|
||||
|
||||
MaxPhoneCodeLength = 4, // max length of country phone code
|
||||
@ -80,8 +78,6 @@ enum {
|
||||
ServiceUserId = 777000,
|
||||
WebPageUserId = 701000,
|
||||
|
||||
CacheBackgroundTimeout = 3000, // cache background scaled image after 3s
|
||||
|
||||
UpdateDelayConstPart = 8 * 3600, // 8 hour min time between update check requests
|
||||
UpdateDelayRandPart = 8 * 3600, // 8 hour max - min time between update check requests
|
||||
|
||||
@ -246,32 +242,6 @@ inline const QString &cTempDir() {
|
||||
return res;
|
||||
}
|
||||
|
||||
enum {
|
||||
DialogsFirstLoad = 20, // first dialogs part size requested
|
||||
DialogsPerPage = 500, // next dialogs part size
|
||||
|
||||
UseBigFilesFrom = 10 * 1024 * 1024, // mtp big files methods used for files greater than 10mb
|
||||
|
||||
UploadPartSize = 32 * 1024, // 32kb for photo
|
||||
DocumentMaxPartsCount = 3000, // no more than 3000 parts
|
||||
DocumentUploadPartSize0 = 32 * 1024, // 32kb for tiny document ( < 1mb )
|
||||
DocumentUploadPartSize1 = 64 * 1024, // 64kb for little document ( <= 32mb )
|
||||
DocumentUploadPartSize2 = 128 * 1024, // 128kb for small document ( <= 375mb )
|
||||
DocumentUploadPartSize3 = 256 * 1024, // 256kb for medium document ( <= 750mb )
|
||||
DocumentUploadPartSize4 = 512 * 1024, // 512kb for large document ( <= 1500mb )
|
||||
UploadRequestInterval = 500, // one part each half second, if not uploaded faster
|
||||
|
||||
MaxPhotosInMemory = 50, // try to clear some memory after 50 photos are created
|
||||
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 ping
|
||||
WaitForSkippedTimeout = 1000, // 1s wait for skipped seq or pts in updates
|
||||
WaitForChannelGetDifference = 1000, // 1s wait after show channel history before sending getChannelDifference
|
||||
|
||||
IdleMsecs = 60 * 1000, // after 60secs without user input we think we are idle
|
||||
|
||||
SendViewsTimeout = 1000, // send views each second
|
||||
};
|
||||
|
||||
inline const QRegularExpression &cRussianLetters() {
|
||||
static QRegularExpression regexp(QString::fromUtf8("[а-яА-ЯёЁ]"));
|
||||
return regexp;
|
||||
|
@ -806,7 +806,7 @@ void LastCrashedWindow::onNetworkSettingsSaved(
|
||||
proxy.user = username;
|
||||
proxy.password = password;
|
||||
|
||||
Sandbox::refreshGlobalProxy();
|
||||
Core::App().refreshGlobalProxy();
|
||||
|
||||
if (_updaterData
|
||||
&& ((_updaterData->state == UpdatingCheck)
|
||||
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "core/single_timer.h"
|
||||
|
||||
#include "application.h"
|
||||
|
||||
SingleTimer::SingleTimer(QObject *parent) : QTimer(parent) {
|
||||
QTimer::setSingleShot(true);
|
||||
Sandbox::connect(SIGNAL(adjustSingleTimers()), this, SLOT(adjust()));
|
||||
}
|
||||
|
||||
void SingleTimer::setTimeoutHandler(Fn<void()> handler) {
|
||||
if (_handler && !handler) {
|
||||
disconnect(this, SIGNAL(timeout()), this, SLOT(onTimeout()));
|
||||
} else if (handler && !_handler) {
|
||||
connect(this, SIGNAL(timeout()), this, SLOT(onTimeout()));
|
||||
}
|
||||
_handler = std::move(handler);
|
||||
}
|
||||
|
||||
void SingleTimer::adjust() {
|
||||
auto n = getms(true);
|
||||
if (isActive()) {
|
||||
if (n >= _finishing) {
|
||||
start(0);
|
||||
} else {
|
||||
start(_finishing - n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SingleTimer::onTimeout() {
|
||||
if (_handler) {
|
||||
_handler();
|
||||
}
|
||||
}
|
||||
|
||||
void SingleTimer::start(int msec) {
|
||||
_finishing = getms(true) + (msec < 0 ? 0 : msec);
|
||||
QTimer::start(msec);
|
||||
}
|
||||
|
||||
void SingleTimer::startIfNotActive(int msec) {
|
||||
if (isActive()) {
|
||||
int remains = remainingTime();
|
||||
if (remains > msec) {
|
||||
start(msec);
|
||||
} else if (!remains) {
|
||||
start(1);
|
||||
}
|
||||
} else {
|
||||
start(msec);
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
class SingleTimer : public QTimer { // single shot timer with check
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SingleTimer(QObject *parent = nullptr);
|
||||
|
||||
void setSingleShot(bool); // is not available
|
||||
void start(); // is not available
|
||||
|
||||
void setTimeoutHandler(Fn<void()> handler);
|
||||
|
||||
public slots:
|
||||
void start(int msec);
|
||||
void startIfNotActive(int msec);
|
||||
|
||||
private slots:
|
||||
void adjust();
|
||||
void onTimeout();
|
||||
|
||||
private:
|
||||
TimeMs _finishing = 0;
|
||||
Fn<void()> _handler;
|
||||
|
||||
};
|
@ -8,7 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "core/utils.h"
|
||||
|
||||
#include "base/qthelp_url.h"
|
||||
#include "application.h"
|
||||
#include "base/timer.h"
|
||||
#include "base/concurrent_timer.h"
|
||||
#include "platform/platform_specific.h"
|
||||
|
||||
extern "C" {
|
||||
@ -84,7 +85,7 @@ std::atomic<int> GlobalAtomicRequestId = 0;
|
||||
}
|
||||
|
||||
TimeId LocalUnixtime() {
|
||||
return (TimeId)time(NULL);
|
||||
return (TimeId)time(nullptr);
|
||||
}
|
||||
|
||||
void unixtimeInit() {
|
||||
@ -173,24 +174,24 @@ namespace {
|
||||
int _ffmpegLockManager(void **mutex, AVLockOp op) {
|
||||
switch (op) {
|
||||
case AV_LOCK_CREATE: {
|
||||
Assert(*mutex == 0);
|
||||
Assert(*mutex == nullptr);
|
||||
*mutex = reinterpret_cast<void*>(new QMutex());
|
||||
} break;
|
||||
|
||||
case AV_LOCK_OBTAIN: {
|
||||
Assert(*mutex != 0);
|
||||
Assert(*mutex != nullptr);
|
||||
reinterpret_cast<QMutex*>(*mutex)->lock();
|
||||
} break;
|
||||
|
||||
case AV_LOCK_RELEASE: {
|
||||
Assert(*mutex != 0);
|
||||
Assert(*mutex != nullptr);
|
||||
reinterpret_cast<QMutex*>(*mutex)->unlock();
|
||||
}; break;
|
||||
|
||||
case AV_LOCK_DESTROY: {
|
||||
Assert(*mutex != 0);
|
||||
Assert(*mutex != nullptr);
|
||||
delete reinterpret_cast<QMutex*>(*mutex);
|
||||
*mutex = 0;
|
||||
*mutex = nullptr;
|
||||
} break;
|
||||
}
|
||||
return 0;
|
||||
@ -428,7 +429,8 @@ namespace ThirdParty {
|
||||
|
||||
bool checkms() {
|
||||
if (crl::adjust_time()) {
|
||||
Sandbox::adjustSingleTimers();
|
||||
base::Timer::Adjust();
|
||||
base::ConcurrentTimerEnvironment::Adjust();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -139,7 +139,8 @@ bool PtsWaiter::updateAndApply(ChannelData *channel, int32 pts, int32 count) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PtsWaiter::check(ChannelData *channel, int32 pts, int32 count) { // return false if need to save that update and apply later
|
||||
// Return false if need to save that update and apply later.
|
||||
bool PtsWaiter::check(ChannelData *channel, int32 pts, int32 count) {
|
||||
if (!inited()) {
|
||||
init(pts);
|
||||
return true;
|
||||
@ -153,7 +154,7 @@ bool PtsWaiter::check(ChannelData *channel, int32 pts, int32 count) { // return
|
||||
} else if (_last < _count) {
|
||||
setWaitingForSkipped(channel, 1);
|
||||
} else {
|
||||
setWaitingForSkipped(channel, WaitForSkippedTimeout);
|
||||
setWaitingForSkipped(channel, kWaitForSkippedTimeout);
|
||||
}
|
||||
return !count;
|
||||
}
|
||||
|
@ -15,6 +15,10 @@ enum PtsSkippedQueue {
|
||||
class PtsWaiter {
|
||||
public:
|
||||
PtsWaiter() = default;
|
||||
|
||||
// 1s wait for skipped seq or pts in updates.
|
||||
static constexpr auto kWaitForSkippedTimeout = 1000;
|
||||
|
||||
void init(int32 pts) {
|
||||
_good = _last = _count = pts;
|
||||
clearSkippedUpdates();
|
||||
|
@ -41,6 +41,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr auto kDialogsFirstLoad = 20;
|
||||
constexpr auto kDialogsPerPage = 500;
|
||||
|
||||
QString SwitchToChooseFromQuery() {
|
||||
return qsl("from:");
|
||||
}
|
||||
@ -877,7 +880,7 @@ void DialogsWidget::loadDialogs() {
|
||||
}
|
||||
|
||||
const auto firstLoad = !_dialogsOffsetDate;
|
||||
const auto loadCount = firstLoad ? DialogsFirstLoad : DialogsPerPage;
|
||||
const auto loadCount = firstLoad ? kDialogsFirstLoad : kDialogsPerPage;
|
||||
const auto flags = MTPmessages_GetDialogs::Flag::f_exclude_pinned;
|
||||
const auto feedId = 0;
|
||||
const auto hash = 0;
|
||||
|
@ -182,8 +182,6 @@ void WorkingDirReady();
|
||||
void WriteInstallBetaVersionsSetting();
|
||||
void WriteDebugModeSetting();
|
||||
|
||||
void MainThreadTaskAdded();
|
||||
|
||||
void start();
|
||||
bool started();
|
||||
void finish();
|
||||
|
@ -39,7 +39,7 @@ class HistoryInner
|
||||
: public Ui::RpWidget
|
||||
, public Ui::AbstractTooltipShower
|
||||
, private base::Subscriber {
|
||||
// The Q_OBJECT meta info is used for qobject_cast to HistoryInner!
|
||||
// The Q_OBJECT meta info is used for qobject_cast!
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -176,6 +176,7 @@ HistoryWidget::HistoryWidget(
|
||||
QWidget *parent,
|
||||
not_null<Window::Controller*> controller)
|
||||
: Window::AbstractSectionWidget(parent, controller)
|
||||
, _updateEditTimeLeftDisplay([=] { updateField(); })
|
||||
, _fieldBarCancel(this, st::historyReplyCancel)
|
||||
, _previewTimer([=] { requestPreview(); })
|
||||
, _topBar(this, controller)
|
||||
@ -360,8 +361,6 @@ HistoryWidget::HistoryWidget(
|
||||
ActivateWindow(this->controller());
|
||||
});
|
||||
|
||||
connect(&_updateEditTimeLeftDisplay, SIGNAL(timeout()), this, SLOT(updateField()));
|
||||
|
||||
subscribe(Adaptive::Changed(), [this] { update(); });
|
||||
Auth().data().itemRemoved(
|
||||
) | rpl::start_with_next(
|
||||
@ -6425,7 +6424,7 @@ void HistoryWidget::paintEditHeader(Painter &p, const QRect &rect, int left, int
|
||||
|
||||
// Restart timer only if we are sure that we've painted the whole timer.
|
||||
if (rect.contains(myrtlrect(left, top, width() - left, st::normalFont->height)) && updateIn > 0) {
|
||||
_updateEditTimeLeftDisplay.start(updateIn);
|
||||
_updateEditTimeLeftDisplay.callOnce(updateIn);
|
||||
}
|
||||
|
||||
if (!editTimeLeftText.isEmpty()) {
|
||||
|
@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "mainwidget.h"
|
||||
#include "chat_helpers/field_autocomplete.h"
|
||||
#include "window/section_widget.h"
|
||||
#include "core/single_timer.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/rp_widget.h"
|
||||
#include "base/flags.h"
|
||||
@ -358,14 +357,13 @@ private slots:
|
||||
|
||||
void onModerateKeyActivate(int index, bool *outHandled);
|
||||
|
||||
void updateField();
|
||||
|
||||
private:
|
||||
using TabbedPanel = ChatHelpers::TabbedPanel;
|
||||
using TabbedSelector = ChatHelpers::TabbedSelector;
|
||||
using DragState = Storage::MimeDataState;
|
||||
|
||||
void initTabbedSelector();
|
||||
void updateField();
|
||||
|
||||
void send(Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers());
|
||||
void handlePendingHistoryUpdate();
|
||||
@ -516,7 +514,7 @@ private:
|
||||
|
||||
HistoryItem *_replyEditMsg = nullptr;
|
||||
Text _replyEditMsgText;
|
||||
mutable SingleTimer _updateEditTimeLeftDisplay;
|
||||
mutable base::Timer _updateEditTimeLeftDisplay;
|
||||
|
||||
object_ptr<Ui::IconButton> _fieldBarCancel;
|
||||
void updateReplyEditTexts(bool force = false);
|
||||
|
@ -40,7 +40,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "auth_session.h"
|
||||
#include "messenger.h"
|
||||
#include "apiwrap.h"
|
||||
#include "application.h"
|
||||
#include "styles/style_info.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
||||
@ -293,7 +292,7 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
|
||||
auto link = Messenger::Instance().createInternalLinkFull(
|
||||
peer->userName());
|
||||
if (!link.isEmpty()) {
|
||||
Application::clipboard()->setText(link);
|
||||
QApplication::clipboard()->setText(link);
|
||||
Ui::Toast::Show(lang(lng_username_copied));
|
||||
}
|
||||
return false;
|
||||
|
@ -100,6 +100,23 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr auto kChannelGetDifferenceLimit = 100;
|
||||
|
||||
// 1s wait after show channel history before sending getChannelDifference.
|
||||
constexpr auto kWaitForChannelGetDifference = TimeMs(1000);
|
||||
|
||||
// If nothing is received in 1 min we ping.
|
||||
constexpr auto kNoUpdatesTimeout = 60 * 1000;
|
||||
|
||||
// If nothing is received in 1 min when was a sleepmode we ping.
|
||||
constexpr auto kNoUpdatesAfterSleepTimeout = 60 * TimeMs(1000);
|
||||
|
||||
// Send channel views each second.
|
||||
constexpr auto kSendViewsTimeout = TimeMs(1000);
|
||||
|
||||
// Cache background scaled image after 3s.
|
||||
constexpr auto kCacheBackgroundTimeout = 3000;
|
||||
|
||||
bool IsForceLogoutNotification(const MTPDupdateServiceNotification &data) {
|
||||
return qs(data.vtype).startsWith(qstr("AUTH_KEY_DROP_"));
|
||||
}
|
||||
@ -239,7 +256,16 @@ MainWidget::MainWidget(
|
||||
this,
|
||||
_controller,
|
||||
Media::Player::Panel::Layout::OnlyPlaylist)
|
||||
, _playerPanel(this, _controller, Media::Player::Panel::Layout::Full) {
|
||||
, _playerPanel(this, _controller, Media::Player::Panel::Layout::Full)
|
||||
, _noUpdatesTimer([=] { sendPing(); })
|
||||
, _byPtsTimer([=] { getDifferenceByPts(); })
|
||||
, _bySeqTimer([=] { getDifference(); })
|
||||
, _byMinChannelTimer([=] { getDifference(); })
|
||||
, _onlineTimer([=] { updateOnline(); })
|
||||
, _idleFinishTimer([=] { checkIdleFinish(); })
|
||||
, _failDifferenceTimer([=] { getDifferenceAfterFail(); })
|
||||
, _cacheBackgroundTimer([=] { cacheBackground(); })
|
||||
, _viewsIncrementTimer([=] { viewsIncrement(); }) {
|
||||
Messenger::Instance().mtp()->setUpdatesHandler(rpcDone(&MainWidget::updateReceived));
|
||||
Messenger::Instance().mtp()->setGlobalFailHandler(rpcFail(&MainWidget::updateFail));
|
||||
|
||||
@ -256,13 +282,6 @@ MainWidget::MainWidget(
|
||||
connect(_dialogs, SIGNAL(cancelled()), this, SLOT(dialogsCancelled()));
|
||||
connect(this, SIGNAL(dialogsUpdated()), _dialogs, SLOT(onListScroll()));
|
||||
connect(_history, SIGNAL(cancelled()), _dialogs, SLOT(activate()));
|
||||
connect(&noUpdatesTimer, SIGNAL(timeout()), this, SLOT(mtpPing()));
|
||||
connect(&_onlineTimer, SIGNAL(timeout()), this, SLOT(updateOnline()));
|
||||
connect(&_idleFinishTimer, SIGNAL(timeout()), this, SLOT(checkIdleFinish()));
|
||||
connect(&_bySeqTimer, SIGNAL(timeout()), this, SLOT(getDifference()));
|
||||
connect(&_byPtsTimer, SIGNAL(timeout()), this, SLOT(onGetDifferenceTimeByPts()));
|
||||
connect(&_byMinChannelTimer, SIGNAL(timeout()), this, SLOT(getDifference()));
|
||||
connect(&_failDifferenceTimer, SIGNAL(timeout()), this, SLOT(onGetDifferenceTimeAfterFail()));
|
||||
subscribe(Media::Player::Updated(), [this](const AudioMsgId &audioId) {
|
||||
if (audioId.type() != AudioMsgId::Type::Video) {
|
||||
handleAudioUpdate(audioId);
|
||||
@ -310,15 +329,12 @@ MainWidget::MainWidget(
|
||||
|
||||
QCoreApplication::instance()->installEventFilter(this);
|
||||
|
||||
connect(&_viewsIncrementTimer, SIGNAL(timeout()), this, SLOT(onViewsIncrement()));
|
||||
|
||||
using Update = Window::Theme::BackgroundUpdate;
|
||||
subscribe(Window::Theme::Background(), [this](const Update &update) {
|
||||
if (update.type == Update::Type::New || update.type == Update::Type::Changed) {
|
||||
clearCachedBackground();
|
||||
}
|
||||
});
|
||||
connect(&_cacheBackgroundTimer, SIGNAL(timeout()), this, SLOT(onCacheBackground()));
|
||||
|
||||
_playerPanel->setPinCallback([this] { switchToFixedPlayer(); });
|
||||
_playerPanel->setCloseCallback([this] { closeBothPlayers(); });
|
||||
@ -925,7 +941,7 @@ bool MainWidget::sendMessageFail(const RPCError &error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void MainWidget::onCacheBackground() {
|
||||
void MainWidget::cacheBackground() {
|
||||
if (Window::Theme::Background()->color()) {
|
||||
return;
|
||||
} else if (Window::Theme::Background()->tile()) {
|
||||
@ -1025,7 +1041,7 @@ void MainWidget::itemEdited(not_null<HistoryItem*> item) {
|
||||
|
||||
void MainWidget::checkLastUpdate(bool afterSleep) {
|
||||
auto n = getms(true);
|
||||
if (_lastUpdateTime && n > _lastUpdateTime + (afterSleep ? NoUpdatesAfterSleepTimeout : NoUpdatesTimeout)) {
|
||||
if (_lastUpdateTime && n > _lastUpdateTime + (afterSleep ? kNoUpdatesAfterSleepTimeout : kNoUpdatesTimeout)) {
|
||||
_lastUpdateTime = n;
|
||||
MTP::ping();
|
||||
}
|
||||
@ -1399,7 +1415,7 @@ bool MainWidget::isIdle() const {
|
||||
|
||||
void MainWidget::clearCachedBackground() {
|
||||
_cachedBackground = QPixmap();
|
||||
_cacheBackgroundTimer.stop();
|
||||
_cacheBackgroundTimer.cancel();
|
||||
update();
|
||||
}
|
||||
|
||||
@ -1411,7 +1427,7 @@ QPixmap MainWidget::cachedBackground(const QRect &forRect, int &x, int &y) {
|
||||
}
|
||||
if (_willCacheFor != forRect || !_cacheBackgroundTimer.isActive()) {
|
||||
_willCacheFor = forRect;
|
||||
_cacheBackgroundTimer.start(CacheBackgroundTimeout);
|
||||
_cacheBackgroundTimer.callOnce(kCacheBackgroundTimeout);
|
||||
}
|
||||
return QPixmap();
|
||||
}
|
||||
@ -1562,12 +1578,12 @@ void MainWidget::scheduleViewIncrement(HistoryItem *item) {
|
||||
auto j = _viewsToIncrement.find(peer);
|
||||
if (j == _viewsToIncrement.cend()) {
|
||||
j = _viewsToIncrement.insert(peer, ViewsIncrementMap());
|
||||
_viewsIncrementTimer.start(SendViewsTimeout);
|
||||
_viewsIncrementTimer.callOnce(kSendViewsTimeout);
|
||||
}
|
||||
j.value().insert(item->id, true);
|
||||
}
|
||||
|
||||
void MainWidget::onViewsIncrement() {
|
||||
void MainWidget::viewsIncrement() {
|
||||
for (auto i = _viewsToIncrement.begin(); i != _viewsToIncrement.cend();) {
|
||||
if (_viewsIncrementRequests.contains(i.key())) {
|
||||
++i;
|
||||
@ -1603,7 +1619,7 @@ void MainWidget::viewsIncrementDone(QVector<MTPint> ids, const MTPVector<MTPint>
|
||||
}
|
||||
}
|
||||
if (!_viewsToIncrement.isEmpty() && !_viewsIncrementTimer.isActive()) {
|
||||
_viewsIncrementTimer.start(SendViewsTimeout);
|
||||
_viewsIncrementTimer.callOnce(kSendViewsTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1617,7 +1633,7 @@ bool MainWidget::viewsIncrementFail(const RPCError &error, mtpRequestId req) {
|
||||
}
|
||||
}
|
||||
if (!_viewsToIncrement.isEmpty() && !_viewsIncrementTimer.isActive()) {
|
||||
_viewsIncrementTimer.start(SendViewsTimeout);
|
||||
_viewsIncrementTimer.callOnce(kSendViewsTimeout);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -1775,7 +1791,7 @@ void MainWidget::ui_showPeerHistory(
|
||||
if (nowActivePeer && nowActivePeer != wasActivePeer) {
|
||||
if (const auto channel = nowActivePeer->asChannel()) {
|
||||
channel->ptsWaitingForShortPoll(
|
||||
WaitForChannelGetDifference);
|
||||
kWaitForChannelGetDifference);
|
||||
}
|
||||
_viewsIncremented.remove(nowActivePeer);
|
||||
}
|
||||
@ -2787,7 +2803,7 @@ void MainWidget::keyPressEvent(QKeyEvent *e) {
|
||||
|
||||
bool MainWidget::eventFilter(QObject *o, QEvent *e) {
|
||||
if (e->type() == QEvent::FocusIn) {
|
||||
if (auto widget = qobject_cast<QWidget*>(o)) {
|
||||
if (const auto widget = qobject_cast<QWidget*>(o)) {
|
||||
if (_history == widget || _history->isAncestorOf(widget)
|
||||
|| (_mainSection && (_mainSection == widget || _mainSection->isAncestorOf(widget)))
|
||||
|| (_thirdSection && (_thirdSection == widget || _thirdSection->isAncestorOf(widget)))) {
|
||||
@ -2928,7 +2944,9 @@ void MainWidget::updSetState(int32 pts, int32 date, int32 qts, int32 seq) {
|
||||
}
|
||||
if (seq && seq != updSeq) {
|
||||
updSeq = seq;
|
||||
if (_bySeqTimer.isActive()) _bySeqTimer.stop();
|
||||
if (_bySeqTimer.isActive()) {
|
||||
_bySeqTimer.cancel();
|
||||
}
|
||||
for (QMap<int32, MTPUpdates>::iterator i = _bySeqUpdates.begin(); i != _bySeqUpdates.end();) {
|
||||
int32 s = i.key();
|
||||
if (s <= seq + 1) {
|
||||
@ -2938,7 +2956,9 @@ void MainWidget::updSetState(int32 pts, int32 date, int32 qts, int32 seq) {
|
||||
return feedUpdates(v);
|
||||
}
|
||||
} else {
|
||||
if (!_bySeqTimer.isActive()) _bySeqTimer.start(WaitForSkippedTimeout);
|
||||
if (!_bySeqTimer.isActive()) {
|
||||
_bySeqTimer.callOnce(PtsWaiter::kWaitForSkippedTimeout);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -3008,7 +3028,9 @@ void MainWidget::gotChannelDifference(
|
||||
MTP_LOG(0, ("getChannelDifference { good - after not final channelDifference was received }%1").arg(cTestMode() ? " TESTMODE" : ""));
|
||||
getChannelDifference(channel);
|
||||
} else if (_controller->activeChatCurrent().peer() == channel) {
|
||||
channel->ptsWaitingForShortPoll(timeout ? (timeout * 1000) : WaitForChannelGetDifference);
|
||||
channel->ptsWaitingForShortPoll(timeout
|
||||
? (timeout * TimeMs(1000))
|
||||
: kWaitForChannelGetDifference);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3037,7 +3059,7 @@ void MainWidget::gotState(const MTPupdates_State &state) {
|
||||
updSetState(d.vpts.v, d.vdate.v, d.vqts.v, d.vseq.v);
|
||||
|
||||
_lastUpdateTime = getms(true);
|
||||
noUpdatesTimer.start(NoUpdatesTimeout);
|
||||
_noUpdatesTimer.callOnce(kNoUpdatesTimeout);
|
||||
_ptsWaiter.setRequesting(false);
|
||||
|
||||
_dialogs->loadDialogs();
|
||||
@ -3053,7 +3075,7 @@ void MainWidget::gotDifference(const MTPupdates_Difference &difference) {
|
||||
updSetState(_ptsWaiter.current(), d.vdate.v, updQts, d.vseq.v);
|
||||
|
||||
_lastUpdateTime = getms(true);
|
||||
noUpdatesTimer.start(NoUpdatesTimeout);
|
||||
_noUpdatesTimer.callOnce(kNoUpdatesTimeout);
|
||||
|
||||
_ptsWaiter.setRequesting(false);
|
||||
} break;
|
||||
@ -3125,7 +3147,7 @@ bool MainWidget::getDifferenceTimeChanged(ChannelData *channel, int32 ms, Channe
|
||||
|
||||
void MainWidget::ptsWaiterStartTimerFor(ChannelData *channel, int32 ms) {
|
||||
if (getDifferenceTimeChanged(channel, ms, _channelGetDifferenceTimeByPts, _getDifferenceTimeByPts)) {
|
||||
onGetDifferenceTimeByPts();
|
||||
getDifferenceByPts();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3140,7 +3162,7 @@ void MainWidget::failDifferenceStartTimerFor(ChannelData *channel) {
|
||||
: i.value();
|
||||
}();
|
||||
if (getDifferenceTimeChanged(channel, timeout * 1000, _channelGetDifferenceTimeAfterFail, _getDifferenceTimeAfterFail)) {
|
||||
onGetDifferenceTimeAfterFail();
|
||||
getDifferenceAfterFail();
|
||||
}
|
||||
if (timeout < 64) timeout *= 2;
|
||||
}
|
||||
@ -3174,11 +3196,11 @@ bool MainWidget::failDifference(const RPCError &error) {
|
||||
if (MTP::isDefaultHandledError(error)) return false;
|
||||
|
||||
LOG(("RPC Error in getDifference: %1 %2: %3").arg(error.code()).arg(error.type()).arg(error.description()));
|
||||
failDifferenceStartTimerFor(0);
|
||||
failDifferenceStartTimerFor(nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWidget::onGetDifferenceTimeByPts() {
|
||||
void MainWidget::getDifferenceByPts() {
|
||||
auto now = getms(true), wait = 0LL;
|
||||
if (_getDifferenceTimeByPts) {
|
||||
if (_getDifferenceTimeByPts > now) {
|
||||
@ -3197,13 +3219,13 @@ void MainWidget::onGetDifferenceTimeByPts() {
|
||||
}
|
||||
}
|
||||
if (wait) {
|
||||
_byPtsTimer.start(wait);
|
||||
_byPtsTimer.callOnce(wait);
|
||||
} else {
|
||||
_byPtsTimer.stop();
|
||||
_byPtsTimer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::onGetDifferenceTimeAfterFail() {
|
||||
void MainWidget::getDifferenceAfterFail() {
|
||||
auto now = getms(true), wait = 0LL;
|
||||
if (_getDifferenceTimeAfterFail) {
|
||||
if (_getDifferenceTimeAfterFail > now) {
|
||||
@ -3224,9 +3246,9 @@ void MainWidget::onGetDifferenceTimeAfterFail() {
|
||||
}
|
||||
}
|
||||
if (wait) {
|
||||
_failDifferenceTimer.start(wait);
|
||||
_failDifferenceTimer.callOnce(wait);
|
||||
} else {
|
||||
_failDifferenceTimer.stop();
|
||||
_failDifferenceTimer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3238,14 +3260,22 @@ void MainWidget::getDifference() {
|
||||
if (requestingDifference()) return;
|
||||
|
||||
_bySeqUpdates.clear();
|
||||
_bySeqTimer.stop();
|
||||
_bySeqTimer.cancel();
|
||||
|
||||
noUpdatesTimer.stop();
|
||||
_noUpdatesTimer.cancel();
|
||||
_getDifferenceTimeAfterFail = 0;
|
||||
|
||||
_ptsWaiter.setRequesting(true);
|
||||
|
||||
MTP::send(MTPupdates_GetDifference(MTP_flags(0), MTP_int(_ptsWaiter.current()), MTPint(), MTP_int(updDate), MTP_int(updQts)), rpcDone(&MainWidget::gotDifference), rpcFail(&MainWidget::failDifference));
|
||||
MTP::send(
|
||||
MTPupdates_GetDifference(
|
||||
MTP_flags(0),
|
||||
MTP_int(_ptsWaiter.current()),
|
||||
MTPint(),
|
||||
MTP_int(updDate),
|
||||
MTP_int(updQts)),
|
||||
rpcDone(&MainWidget::gotDifference),
|
||||
rpcFail(&MainWidget::failDifference));
|
||||
}
|
||||
|
||||
void MainWidget::getChannelDifference(ChannelData *channel, ChannelDifferenceRequest from) {
|
||||
@ -3270,10 +3300,18 @@ void MainWidget::getChannelDifference(ChannelData *channel, ChannelDifferenceReq
|
||||
flags = 0; // No force flag when requesting for short poll.
|
||||
}
|
||||
}
|
||||
MTP::send(MTPupdates_GetChannelDifference(MTP_flags(flags), channel->inputChannel, filter, MTP_int(channel->pts()), MTP_int(MTPChannelGetDifferenceLimit)), rpcDone(&MainWidget::gotChannelDifference, channel), rpcFail(&MainWidget::failChannelDifference, channel));
|
||||
MTP::send(
|
||||
MTPupdates_GetChannelDifference(
|
||||
MTP_flags(flags),
|
||||
channel->inputChannel,
|
||||
filter,
|
||||
MTP_int(channel->pts()),
|
||||
MTP_int(kChannelGetDifferenceLimit)),
|
||||
rpcDone(&MainWidget::gotChannelDifference, channel),
|
||||
rpcFail(&MainWidget::failChannelDifference, channel));
|
||||
}
|
||||
|
||||
void MainWidget::mtpPing() {
|
||||
void MainWidget::sendPing() {
|
||||
MTP::ping();
|
||||
}
|
||||
|
||||
@ -3470,7 +3508,7 @@ void MainWidget::incrementSticker(DocumentData *sticker) {
|
||||
it->stickers.removeAt(index);
|
||||
for (auto i = it->emoji.begin(); i != it->emoji.end();) {
|
||||
if (const auto index = i->indexOf(sticker); index >= 0) {
|
||||
removedFromEmoji.push_back(i.key());
|
||||
removedFromEmoji.emplace_back(i.key());
|
||||
i->removeAt(index);
|
||||
if (i->isEmpty()) {
|
||||
i = it->emoji.erase(i);
|
||||
@ -3620,7 +3658,7 @@ void MainWidget::updateOnline(bool gotOtherOffline) {
|
||||
isOnline = false;
|
||||
if (!_isIdle) {
|
||||
_isIdle = true;
|
||||
_idleFinishTimer.start(900);
|
||||
_idleFinishTimer.callOnce(900);
|
||||
}
|
||||
} else {
|
||||
updateIn = qMin(updateIn, int(Global::OfflineIdleTimeout() - idle));
|
||||
@ -3652,7 +3690,7 @@ void MainWidget::updateOnline(bool gotOtherOffline) {
|
||||
} else if (isOnline) {
|
||||
updateIn = qMin(updateIn, int(_lastSetOnline + Global::OnlineUpdatePeriod() - ms));
|
||||
}
|
||||
_onlineTimer.start(updateIn);
|
||||
_onlineTimer.callOnce(updateIn);
|
||||
}
|
||||
|
||||
void MainWidget::saveDraftToCloud() {
|
||||
@ -3703,14 +3741,13 @@ void MainWidget::writeDrafts(History *history) {
|
||||
}
|
||||
|
||||
void MainWidget::checkIdleFinish() {
|
||||
if (this != App::main()) return;
|
||||
if (psIdleTime() < Global::OfflineIdleTimeout()) {
|
||||
_idleFinishTimer.stop();
|
||||
_idleFinishTimer.cancel();
|
||||
_isIdle = false;
|
||||
updateOnline();
|
||||
if (App::wnd()) App::wnd()->checkHistoryActivation();
|
||||
App::wnd()->checkHistoryActivation();
|
||||
} else {
|
||||
_idleFinishTimer.start(900);
|
||||
_idleFinishTimer.callOnce(900);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3734,7 +3771,7 @@ void MainWidget::updateReceived(const mtpPrime *from, const mtpPrime *end) {
|
||||
updates.read(from, end);
|
||||
|
||||
_lastUpdateTime = getms(true);
|
||||
noUpdatesTimer.start(NoUpdatesTimeout);
|
||||
_noUpdatesTimer.callOnce(kNoUpdatesTimeout);
|
||||
if (!requestingDifference()
|
||||
|| HasForceLogoutNotification(updates)) {
|
||||
feedUpdates(updates);
|
||||
@ -3860,7 +3897,8 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
||||
}
|
||||
if (d.vseq.v > updSeq + 1) {
|
||||
_bySeqUpdates.insert(d.vseq.v, updates);
|
||||
return _bySeqTimer.start(WaitForSkippedTimeout);
|
||||
_bySeqTimer.callOnce(PtsWaiter::kWaitForSkippedTimeout);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3879,7 +3917,8 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) {
|
||||
}
|
||||
if (d.vseq_start.v > updSeq + 1) {
|
||||
_bySeqUpdates.insert(d.vseq_start.v, updates);
|
||||
return _bySeqTimer.start(WaitForSkippedTimeout);
|
||||
_bySeqTimer.callOnce(PtsWaiter::kWaitForSkippedTimeout);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4019,7 +4058,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
|
||||
}
|
||||
|
||||
if (!_byMinChannelTimer.isActive()) { // getDifference after timeout
|
||||
_byMinChannelTimer.start(WaitForSkippedTimeout);
|
||||
_byMinChannelTimer.callOnce(PtsWaiter::kWaitForSkippedTimeout);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -4068,7 +4107,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
|
||||
if (!channel) {
|
||||
if (!_byMinChannelTimer.isActive()) {
|
||||
// getDifference after timeout.
|
||||
_byMinChannelTimer.start(WaitForSkippedTimeout);
|
||||
_byMinChannelTimer.callOnce(PtsWaiter::kWaitForSkippedTimeout);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -4615,13 +4654,13 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
|
||||
auto &v = set.vdocuments.v;
|
||||
it->stickers.clear();
|
||||
it->stickers.reserve(v.size());
|
||||
for (int i = 0, l = v.size(); i < l; ++i) {
|
||||
const auto doc = Auth().data().document(v.at(i));
|
||||
if (!doc->sticker()) continue;
|
||||
for (const auto &item : v) {
|
||||
const auto document = Auth().data().document(item);
|
||||
if (!document->sticker()) continue;
|
||||
|
||||
it->stickers.push_back(doc);
|
||||
if (doc->sticker()->set.type() != mtpc_inputStickerSetID) {
|
||||
doc->sticker()->set = inputSet;
|
||||
it->stickers.push_back(document);
|
||||
if (document->sticker()->set.type() != mtpc_inputStickerSetID) {
|
||||
document->sticker()->set = inputSet;
|
||||
}
|
||||
}
|
||||
it->emoji.clear();
|
||||
@ -4678,11 +4717,11 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
|
||||
auto &order = d.vorder.v;
|
||||
auto &sets = Auth().data().stickerSets();
|
||||
Stickers::Order result;
|
||||
for (int i = 0, l = order.size(); i < l; ++i) {
|
||||
if (sets.constFind(order.at(i).v) == sets.cend()) {
|
||||
for (const auto &item : order) {
|
||||
if (sets.constFind(item.v) == sets.cend()) {
|
||||
break;
|
||||
}
|
||||
result.push_back(order.at(i).v);
|
||||
result.push_back(item.v);
|
||||
}
|
||||
if (result.size() != Auth().data().stickerSetsOrder().size() || result.size() != order.size()) {
|
||||
Auth().data().setLastStickersUpdate(0);
|
||||
|
@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "core/single_timer.h"
|
||||
#include "base/timer.h"
|
||||
#include "base/weak_ptr.h"
|
||||
#include "ui/rp_widget.h"
|
||||
#include "media/player/media_player_float.h"
|
||||
@ -257,11 +257,14 @@ public:
|
||||
|
||||
void feedChannelDifference(const MTPDupdates_channelDifference &data);
|
||||
|
||||
// Mayde public for ApiWrap, while it is still here.
|
||||
// Made public for ApiWrap, while it is still here.
|
||||
// Better would be for this to be moved to ApiWrap.
|
||||
bool requestingDifference() const {
|
||||
return _ptsWaiter.requesting();
|
||||
}
|
||||
void getDifference();
|
||||
void updateOnline(bool gotOtherOffline = false);
|
||||
void checkIdleFinish();
|
||||
|
||||
bool contentOverlapped(const QRect &globalRect);
|
||||
|
||||
@ -307,18 +310,6 @@ public slots:
|
||||
|
||||
void dialogsCancelled();
|
||||
|
||||
void getDifference();
|
||||
void onGetDifferenceTimeByPts();
|
||||
void onGetDifferenceTimeAfterFail();
|
||||
void mtpPing();
|
||||
|
||||
void updateOnline(bool gotOtherOffline = false);
|
||||
void checkIdleFinish();
|
||||
|
||||
void onCacheBackground();
|
||||
|
||||
void onViewsIncrement();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
@ -343,6 +334,11 @@ private:
|
||||
UserData *from;
|
||||
};
|
||||
|
||||
void viewsIncrement();
|
||||
void sendPing();
|
||||
void getDifferenceByPts();
|
||||
void getDifferenceAfterFail();
|
||||
|
||||
void animationCallback();
|
||||
void handleAdaptiveLayoutUpdate();
|
||||
void updateWindowAdaptiveLayout();
|
||||
@ -429,6 +425,7 @@ private:
|
||||
void showAll();
|
||||
void clearHider(not_null<Window::HistoryHider*> instance);
|
||||
|
||||
void cacheBackground();
|
||||
void clearCachedBackground();
|
||||
|
||||
not_null<Media::Player::FloatDelegate*> floatPlayerDelegate();
|
||||
@ -510,7 +507,7 @@ private:
|
||||
int32 updDate = 0;
|
||||
int32 updQts = -1;
|
||||
int32 updSeq = 0;
|
||||
SingleTimer noUpdatesTimer;
|
||||
base::Timer _noUpdatesTimer;
|
||||
|
||||
PtsWaiter _ptsWaiter;
|
||||
|
||||
@ -518,22 +515,23 @@ private:
|
||||
TimeMs _getDifferenceTimeByPts = 0;
|
||||
TimeMs _getDifferenceTimeAfterFail = 0;
|
||||
|
||||
SingleTimer _byPtsTimer;
|
||||
base::Timer _byPtsTimer;
|
||||
|
||||
QMap<int32, MTPUpdates> _bySeqUpdates;
|
||||
SingleTimer _bySeqTimer;
|
||||
base::Timer _bySeqTimer;
|
||||
|
||||
SingleTimer _byMinChannelTimer;
|
||||
base::Timer _byMinChannelTimer;
|
||||
|
||||
mtpRequestId _onlineRequest = 0;
|
||||
SingleTimer _onlineTimer, _idleFinishTimer;
|
||||
base::Timer _onlineTimer;
|
||||
base::Timer _idleFinishTimer;
|
||||
bool _lastWasOnline = false;
|
||||
TimeMs _lastSetOnline = 0;
|
||||
bool _isIdle = false;
|
||||
|
||||
int32 _failDifferenceTimeout = 1; // growing timeout for getDifference calls, if it fails
|
||||
QMap<ChannelData*, int32> _channelFailDifferenceTimeout; // growing timeout for getChannelDifference calls, if it fails
|
||||
SingleTimer _failDifferenceTimer;
|
||||
base::Timer _failDifferenceTimer;
|
||||
|
||||
TimeMs _lastUpdateTime = 0;
|
||||
bool _handlingChannelDifference = false;
|
||||
@ -542,7 +540,7 @@ private:
|
||||
QRect _cachedFor, _willCacheFor;
|
||||
int _cachedX = 0;
|
||||
int _cachedY = 0;
|
||||
SingleTimer _cacheBackgroundTimer;
|
||||
base::Timer _cacheBackgroundTimer;
|
||||
|
||||
PhotoData *_deletingPhoto = nullptr;
|
||||
|
||||
@ -550,7 +548,7 @@ private:
|
||||
QMap<PeerData*, ViewsIncrementMap> _viewsIncremented, _viewsToIncrement;
|
||||
QMap<PeerData*, mtpRequestId> _viewsIncrementRequests;
|
||||
QMap<mtpRequestId, PeerData*> _viewsIncrementByRequest;
|
||||
SingleTimer _viewsIncrementTimer;
|
||||
base::Timer _viewsIncrementTimer;
|
||||
|
||||
struct SettingBackground;
|
||||
std::unique_ptr<SettingBackground> _background;
|
||||
|
@ -714,7 +714,7 @@ void MainWindow::toggleDisplayNotifyFromTray() {
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *e) {
|
||||
if (Sandbox::isSavingSession()) {
|
||||
if (Core::App().isSavingSession()) {
|
||||
e->accept();
|
||||
App::quit();
|
||||
} else {
|
||||
|
@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
#include "platform/platform_specific.h"
|
||||
#include "platform/platform_main_window.h"
|
||||
#include "core/single_timer.h"
|
||||
#include "base/unique_qptr.h"
|
||||
|
||||
class MainWidget;
|
||||
|
@ -906,7 +906,7 @@ void MediaView::onSaveAs() {
|
||||
}));
|
||||
}
|
||||
activateWindow();
|
||||
Sandbox::setActiveWindow(this);
|
||||
Core::App().setActiveWindow(this);
|
||||
setFocus();
|
||||
}
|
||||
|
||||
@ -1777,7 +1777,7 @@ void MediaView::displayFinished() {
|
||||
show();
|
||||
psShowOverAll(this);
|
||||
activateWindow();
|
||||
Sandbox::setActiveWindow(this);
|
||||
Core::App().setActiveWindow(this);
|
||||
setFocus();
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ struct Messenger::Private {
|
||||
Messenger::Messenger(not_null<Core::Launcher*> launcher)
|
||||
: QObject()
|
||||
, _launcher(launcher)
|
||||
, _killDownloadSessionsTimer([=] { killDownloadSessions(); })
|
||||
, _private(std::make_unique<Private>())
|
||||
, _databases(std::make_unique<Storage::Databases>())
|
||||
, _langpack(std::make_unique<Lang::Instance>())
|
||||
@ -95,7 +96,7 @@ Messenger::Messenger(not_null<Core::Launcher*> launcher)
|
||||
|
||||
ThirdParty::start();
|
||||
Global::start();
|
||||
Sandbox::refreshGlobalProxy(); // Depends on Global::started().
|
||||
Core::App().refreshGlobalProxy(); // Depends on Global::started().
|
||||
|
||||
startLocalStorage();
|
||||
|
||||
@ -110,7 +111,7 @@ Messenger::Messenger(not_null<Core::Launcher*> launcher)
|
||||
}
|
||||
|
||||
_translator = std::make_unique<Lang::Translator>();
|
||||
QCoreApplication::instance()->installTranslator(_translator.get());
|
||||
qApp->installTranslator(_translator.get());
|
||||
|
||||
style::startManager();
|
||||
anim::startManager();
|
||||
@ -120,12 +121,10 @@ Messenger::Messenger(not_null<Core::Launcher*> launcher)
|
||||
|
||||
DEBUG_LOG(("Application Info: inited..."));
|
||||
|
||||
QCoreApplication::instance()->installNativeEventFilter(psNativeEventFilter());
|
||||
QApplication::instance()->installNativeEventFilter(psNativeEventFilter());
|
||||
|
||||
cChangeTimeFormat(QLocale::system().timeFormat(QLocale::ShortFormat));
|
||||
|
||||
connect(&killDownloadSessionsTimer, SIGNAL(timeout()), this, SLOT(killDownloadSessions()));
|
||||
|
||||
DEBUG_LOG(("Application Info: starting app..."));
|
||||
|
||||
// Create mime database, so it won't be slow later.
|
||||
@ -138,8 +137,12 @@ Messenger::Messenger(not_null<Core::Launcher*> launcher)
|
||||
_mediaView = std::make_unique<MediaView>();
|
||||
_window->setGeometry(currentGeometry);
|
||||
|
||||
QCoreApplication::instance()->installEventFilter(this);
|
||||
Sandbox::connect(SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onAppStateChanged(Qt::ApplicationState)));
|
||||
qApp->installEventFilter(this);
|
||||
connect(
|
||||
qApp,
|
||||
SIGNAL(applicationStateChanged(Qt::ApplicationState)),
|
||||
this,
|
||||
SLOT(onAppStateChanged(Qt::ApplicationState)));
|
||||
|
||||
DEBUG_LOG(("Application Info: window created..."));
|
||||
|
||||
@ -252,13 +255,13 @@ bool Messenger::eventFilter(QObject *object, QEvent *e) {
|
||||
} break;
|
||||
|
||||
case QEvent::ApplicationActivate: {
|
||||
if (object == QCoreApplication::instance()) {
|
||||
if (object == qApp) {
|
||||
psUserActionDone();
|
||||
}
|
||||
} break;
|
||||
|
||||
case QEvent::FileOpen: {
|
||||
if (object == QCoreApplication::instance()) {
|
||||
if (object == qApp) {
|
||||
auto url = QString::fromUtf8(static_cast<QFileOpenEvent*>(e)->url().toEncoded().trimmed());
|
||||
if (url.startsWith(qstr("tg://"), Qt::CaseInsensitive)) {
|
||||
cSetStartUrl(url.mid(0, 8192));
|
||||
@ -289,7 +292,7 @@ void Messenger::setCurrentProxy(
|
||||
: ProxyData()));
|
||||
Global::SetSelectedProxy(proxy);
|
||||
Global::SetProxySettings(settings);
|
||||
Sandbox::refreshGlobalProxy();
|
||||
Core::App().refreshGlobalProxy();
|
||||
if (_mtproto) {
|
||||
_mtproto->restart();
|
||||
if (previousKey != key(proxy)) {
|
||||
@ -527,13 +530,18 @@ void Messenger::destroyMtpKeys(MTP::AuthKeysList &&keys) {
|
||||
destroyConfig.mainDcId = MTP::Instance::Config::kNoneMainDc;
|
||||
destroyConfig.keys = std::move(keys);
|
||||
_mtprotoForKeysDestroy = std::make_unique<MTP::Instance>(_dcOptions.get(), MTP::Instance::Mode::KeysDestroyer, std::move(destroyConfig));
|
||||
connect(_mtprotoForKeysDestroy.get(), SIGNAL(allKeysDestroyed()), this, SLOT(onAllKeysDestroyed()));
|
||||
connect(
|
||||
_mtprotoForKeysDestroy.get(),
|
||||
&MTP::Instance::allKeysDestroyed,
|
||||
[=] { allKeysDestroyed(); });
|
||||
}
|
||||
|
||||
void Messenger::onAllKeysDestroyed() {
|
||||
void Messenger::allKeysDestroyed() {
|
||||
LOG(("MTP Info: all keys scheduled for destroy are destroyed."));
|
||||
_mtprotoForKeysDestroy.reset();
|
||||
Local::writeMtpData();
|
||||
crl::on_main(this, [=] {
|
||||
_mtprotoForKeysDestroy = nullptr;
|
||||
Local::writeMtpData();
|
||||
});
|
||||
}
|
||||
|
||||
void Messenger::suggestMainDcId(MTP::DcId mainDcId) {
|
||||
@ -601,18 +609,19 @@ void Messenger::startLocalStorage() {
|
||||
}
|
||||
|
||||
void Messenger::killDownloadSessionsStart(MTP::DcId dcId) {
|
||||
if (killDownloadSessionTimes.constFind(dcId) == killDownloadSessionTimes.cend()) {
|
||||
killDownloadSessionTimes.insert(dcId, getms() + MTPAckSendWaiting + MTPKillFileSessionTimeout);
|
||||
if (!_killDownloadSessionTimes.contains(dcId)) {
|
||||
_killDownloadSessionTimes.emplace(dcId, getms() + MTPAckSendWaiting + MTPKillFileSessionTimeout);
|
||||
}
|
||||
if (!killDownloadSessionsTimer.isActive()) {
|
||||
killDownloadSessionsTimer.start(MTPAckSendWaiting + MTPKillFileSessionTimeout + 5);
|
||||
if (!_killDownloadSessionsTimer.isActive()) {
|
||||
_killDownloadSessionsTimer.callOnce(MTPAckSendWaiting + MTPKillFileSessionTimeout + 5);
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::killDownloadSessionsStop(MTP::DcId dcId) {
|
||||
killDownloadSessionTimes.remove(dcId);
|
||||
if (killDownloadSessionTimes.isEmpty() && killDownloadSessionsTimer.isActive()) {
|
||||
killDownloadSessionsTimer.stop();
|
||||
_killDownloadSessionTimes.erase(dcId);
|
||||
if (_killDownloadSessionTimes.empty()
|
||||
&& _killDownloadSessionsTimer.isActive()) {
|
||||
_killDownloadSessionsTimer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@ -673,25 +682,25 @@ void Messenger::call_handleObservables() {
|
||||
|
||||
void Messenger::killDownloadSessions() {
|
||||
auto ms = getms(), left = static_cast<TimeMs>(MTPAckSendWaiting) + MTPKillFileSessionTimeout;
|
||||
for (auto i = killDownloadSessionTimes.begin(); i != killDownloadSessionTimes.end(); ) {
|
||||
if (i.value() <= ms) {
|
||||
for (auto i = _killDownloadSessionTimes.begin(); i != _killDownloadSessionTimes.end(); ) {
|
||||
if (i->second <= ms) {
|
||||
for (int j = 0; j < MTP::kDownloadSessionsCount; ++j) {
|
||||
MTP::stopSession(MTP::downloadDcId(i.key(), j));
|
||||
MTP::stopSession(MTP::downloadDcId(i->first, j));
|
||||
}
|
||||
i = killDownloadSessionTimes.erase(i);
|
||||
i = _killDownloadSessionTimes.erase(i);
|
||||
} else {
|
||||
if (i.value() - ms < left) {
|
||||
left = i.value() - ms;
|
||||
if (i->second - ms < left) {
|
||||
left = i->second - ms;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
if (!killDownloadSessionTimes.isEmpty()) {
|
||||
killDownloadSessionsTimer.start(left);
|
||||
if (!_killDownloadSessionTimes.empty()) {
|
||||
_killDownloadSessionsTimer.callOnce(left);
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::onSwitchDebugMode() {
|
||||
void Messenger::switchDebugMode() {
|
||||
if (Logs::DebugEnabled()) {
|
||||
Logs::SetDebugEnabled(false);
|
||||
Sandbox::WriteDebugModeSetting();
|
||||
@ -704,14 +713,14 @@ void Messenger::onSwitchDebugMode() {
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::onSwitchWorkMode() {
|
||||
void Messenger::switchWorkMode() {
|
||||
Global::SetDialogsModeEnabled(!Global::DialogsModeEnabled());
|
||||
Global::SetDialogsMode(Dialogs::Mode::All);
|
||||
Local::writeUserSettings();
|
||||
App::restart();
|
||||
}
|
||||
|
||||
void Messenger::onSwitchTestMode() {
|
||||
void Messenger::switchTestMode() {
|
||||
if (cTestMode()) {
|
||||
QFile(cWorkingDir() + qsl("tdata/withtestmode")).remove();
|
||||
cSetTestMode(false);
|
||||
@ -971,7 +980,7 @@ QWidget *Messenger::getFileDialogParent() {
|
||||
void Messenger::checkMediaViewActivation() {
|
||||
if (_mediaView && !_mediaView->isHidden()) {
|
||||
_mediaView->activateWindow();
|
||||
Sandbox::setActiveWindow(_mediaView.get());
|
||||
Core::App().setActiveWindow(_mediaView.get());
|
||||
_mediaView->setFocus();
|
||||
}
|
||||
}
|
||||
@ -1062,7 +1071,7 @@ void Messenger::unregisterLeaveSubscription(QWidget *widget) {
|
||||
|
||||
void Messenger::QuitAttempt() {
|
||||
auto prevents = false;
|
||||
if (!Sandbox::isSavingSession() && AuthSession::Exists()) {
|
||||
if (AuthSession::Exists() && !Core::App().isSavingSession()) {
|
||||
if (Auth().api().isQuitPrevent()) {
|
||||
prevents = true;
|
||||
}
|
||||
@ -1073,7 +1082,7 @@ void Messenger::QuitAttempt() {
|
||||
if (prevents) {
|
||||
Instance().quitDelayed();
|
||||
} else {
|
||||
QCoreApplication::quit();
|
||||
QApplication::quit();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1085,7 +1094,7 @@ void Messenger::quitPreventFinished() {
|
||||
|
||||
void Messenger::quitDelayed() {
|
||||
if (!_private->quitTimer.isActive()) {
|
||||
_private->quitTimer.setCallback([] { QCoreApplication::quit(); });
|
||||
_private->quitTimer.setCallback([] { QApplication::quit(); });
|
||||
_private->quitTimer.callOnce(kQuitPreventTimeoutMs);
|
||||
}
|
||||
}
|
||||
|
@ -199,6 +199,10 @@ public:
|
||||
void handleAppActivated();
|
||||
void handleAppDeactivated();
|
||||
|
||||
void switchDebugMode();
|
||||
void switchWorkMode();
|
||||
void switchTestMode();
|
||||
|
||||
void call_handleUnreadCounterUpdate();
|
||||
void call_handleDelayedPeerUpdates();
|
||||
void call_handleObservables();
|
||||
@ -211,17 +215,13 @@ protected:
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
||||
public slots:
|
||||
void onAllKeysDestroyed();
|
||||
|
||||
void onSwitchDebugMode();
|
||||
void onSwitchWorkMode();
|
||||
void onSwitchTestMode();
|
||||
|
||||
void killDownloadSessions();
|
||||
void onAppStateChanged(Qt::ApplicationState state);
|
||||
|
||||
private:
|
||||
void destroyMtpKeys(MTP::AuthKeysList &&keys);
|
||||
void allKeysDestroyed();
|
||||
|
||||
void startLocalStorage();
|
||||
void startShortcuts();
|
||||
|
||||
@ -238,8 +238,8 @@ private:
|
||||
|
||||
not_null<Core::Launcher*> _launcher;
|
||||
|
||||
QMap<MTP::DcId, TimeMs> killDownloadSessionTimes;
|
||||
SingleTimer killDownloadSessionsTimer;
|
||||
base::flat_map<MTP::DcId, TimeMs> _killDownloadSessionTimes;
|
||||
base::Timer _killDownloadSessionsTimer;
|
||||
|
||||
// Some fields are just moved from the declaration.
|
||||
struct Private;
|
||||
|
@ -37,6 +37,7 @@ class RSAPublicKey;
|
||||
struct ConnectionOptions;
|
||||
|
||||
class Thread : public QThread {
|
||||
// The Q_OBJECT meta info is used for qobject_cast!
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "core/single_timer.h"
|
||||
#include "mtproto/type_utils.h"
|
||||
#include "mtproto/mtp_instance.h"
|
||||
|
||||
|
@ -361,7 +361,7 @@ void Instance::Private::setGoodProxyDomain(
|
||||
}
|
||||
if (applyToProxy(Global::RefSelectedProxy())
|
||||
&& (Global::ProxySettings() == ProxyData::Settings::Enabled)) {
|
||||
Sandbox::refreshGlobalProxy();
|
||||
Core::App().refreshGlobalProxy();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,13 +122,12 @@ void SessionData::clear(Instance *instance) {
|
||||
Session::Session(not_null<Instance*> instance, ShiftedDcId shiftedDcId) : QObject()
|
||||
, _instance(instance)
|
||||
, data(this)
|
||||
, dcWithShift(shiftedDcId) {
|
||||
, dcWithShift(shiftedDcId)
|
||||
, sender([=] { needToResumeAndSend(); }) {
|
||||
connect(&timeouter, SIGNAL(timeout()), this, SLOT(checkRequestsByTimer()));
|
||||
timeouter.start(1000);
|
||||
|
||||
refreshOptions();
|
||||
|
||||
connect(&sender, SIGNAL(timeout()), this, SLOT(needToResumeAndSend()));
|
||||
}
|
||||
|
||||
void Session::start() {
|
||||
@ -247,10 +246,10 @@ void Session::sendAnything(qint64 msCanWait) {
|
||||
if (msWait) {
|
||||
DEBUG_LOG(("MTP Info: dcWithShift %1 can wait for %2ms from current %3").arg(dcWithShift).arg(msWait).arg(msSendCall));
|
||||
msSendCall = ms;
|
||||
sender.start(msWait);
|
||||
sender.callOnce(msWait);
|
||||
} else {
|
||||
DEBUG_LOG(("MTP Info: dcWithShift %1 stopped send timer, can wait for %2ms from current %3").arg(dcWithShift).arg(msWait).arg(msSendCall));
|
||||
sender.stop();
|
||||
sender.cancel();
|
||||
msSendCall = 0;
|
||||
needToResumeAndSend();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "core/single_timer.h"
|
||||
#include "base/timer.h"
|
||||
#include "mtproto/rpc_sender.h"
|
||||
|
||||
namespace MTP {
|
||||
@ -394,7 +394,7 @@ private:
|
||||
bool _ping = false;
|
||||
|
||||
QTimer timeouter;
|
||||
SingleTimer sender;
|
||||
base::Timer sender;
|
||||
|
||||
};
|
||||
|
||||
|
@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "lang/lang_keys.h"
|
||||
#include "boxes/abstract_box.h"
|
||||
#include "storage/storage_media_prepare.h"
|
||||
#include "storage/file_upload.h" // For Storage::kUseBigFilesFrom.
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_passport.h"
|
||||
|
||||
@ -31,7 +32,7 @@ constexpr auto kMaxDimensions = 2048;
|
||||
constexpr auto kMaxSize = 10 * 1024 * 1024;
|
||||
constexpr auto kJpegQuality = 89;
|
||||
|
||||
static_assert(kMaxSize <= UseBigFilesFrom);
|
||||
static_assert(kMaxSize <= Storage::kUseBigFilesFrom);
|
||||
|
||||
base::variant<ReadScanError, QByteArray> ProcessImage(QByteArray &&bytes) {
|
||||
auto image = App::readImage(base::take(bytes));
|
||||
|
@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
namespace Platform {
|
||||
|
||||
class MainWindow : public Window::MainWindow {
|
||||
// The Q_OBJECT meta info is used for qobject_cast to MainWindow!
|
||||
// The Q_OBJECT meta info is used for qobject_cast!
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "styles/style_window.h"
|
||||
#include "mainwindow.h"
|
||||
#include "mainwidget.h"
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
#include "auth_session.h"
|
||||
#include "history/history.h"
|
||||
@ -70,7 +69,7 @@ public:
|
||||
LayerCreationChecker(NSView * __weak view, Fn<void()> callback)
|
||||
: _weakView(view)
|
||||
, _callback(std::move(callback)) {
|
||||
QCoreApplication::instance()->installEventFilter(this);
|
||||
QApplication::instance()->installEventFilter(this);
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -334,7 +333,7 @@ bool MainWindow::Private::clipboardHasText() {
|
||||
auto currentChangeCount = static_cast<int>([_generalPasteboard changeCount]);
|
||||
if (_generalPasteboardChangeCount != currentChangeCount) {
|
||||
_generalPasteboardChangeCount = currentChangeCount;
|
||||
_generalPasteboardHasText = !Application::clipboard()->text().isEmpty();
|
||||
_generalPasteboardHasText = !QApplication::clipboard()->text().isEmpty();
|
||||
}
|
||||
return _generalPasteboardHasText;
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
QRect avail(Sandbox::availableGeometry());
|
||||
const auto avail = QApplication::desktop()->availableGeometry();
|
||||
max_w = avail.width();
|
||||
accumulate_max(max_w, st::windowMinWidth);
|
||||
max_h = avail.height();
|
||||
|
@ -374,8 +374,8 @@ private:
|
||||
};
|
||||
|
||||
Manager::Private::Private(Manager *instance, Type type)
|
||||
: _guarded(std::make_shared<Manager*>(instance))
|
||||
, _cachedUserpics(type) {
|
||||
: _cachedUserpics(type)
|
||||
, _guarded(std::make_shared<Manager*>(instance)) {
|
||||
}
|
||||
|
||||
bool Manager::Private::init() {
|
||||
|
@ -34,7 +34,7 @@ auto GenerateCodes() {
|
||||
: qsl("Do you want to enable DEBUG logs?\n\n"
|
||||
"All network events will be logged.");
|
||||
Ui::show(Box<ConfirmBox>(text, [] {
|
||||
Messenger::Instance().onSwitchDebugMode();
|
||||
Messenger::Instance().switchDebugMode();
|
||||
}));
|
||||
});
|
||||
codes.emplace(qsl("viewlogs"), [] {
|
||||
@ -43,7 +43,7 @@ auto GenerateCodes() {
|
||||
codes.emplace(qsl("testmode"), [] {
|
||||
auto text = cTestMode() ? qsl("Do you want to disable TEST mode?") : qsl("Do you want to enable TEST mode?\n\nYou will be switched to test cloud.");
|
||||
Ui::show(Box<ConfirmBox>(text, [] {
|
||||
Messenger::Instance().onSwitchTestMode();
|
||||
Messenger::Instance().switchTestMode();
|
||||
}));
|
||||
});
|
||||
if (!Core::UpdaterDisabled()) {
|
||||
@ -71,7 +71,7 @@ auto GenerateCodes() {
|
||||
codes.emplace(qsl("workmode"), [] {
|
||||
auto text = Global::DialogsModeEnabled() ? qsl("Disable work mode?") : qsl("Enable work mode?");
|
||||
Ui::show(Box<ConfirmBox>(text, [] {
|
||||
Messenger::Instance().onSwitchWorkMode();
|
||||
Messenger::Instance().switchWorkMode();
|
||||
}));
|
||||
});
|
||||
codes.emplace(qsl("moderate"), [] {
|
||||
|
@ -1440,18 +1440,18 @@ void WebLoadManager::onFailed(QNetworkReply *reply) {
|
||||
}
|
||||
|
||||
void WebLoadManager::onProgress(qint64 already, qint64 size) {
|
||||
QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
|
||||
const auto reply = qobject_cast<QNetworkReply*>(QObject::sender());
|
||||
if (!reply) return;
|
||||
|
||||
Replies::iterator j = _replies.find(reply);
|
||||
const auto j = _replies.find(reply);
|
||||
if (j == _replies.cend()) { // handled already
|
||||
return;
|
||||
}
|
||||
webFileLoaderPrivate *loader = j.value();
|
||||
const auto loader = j.value();
|
||||
|
||||
WebReplyProcessResult result = WebReplyProcessProgress;
|
||||
QVariant statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
||||
int32 status = statusCode.isValid() ? statusCode.toInt() : 200;
|
||||
auto result = WebReplyProcessProgress;
|
||||
const auto statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
||||
const auto status = statusCode.isValid() ? statusCode.toInt() : 200;
|
||||
if (status != 200 && status != 206 && status != 416) {
|
||||
if (status == 301 || status == 302) {
|
||||
QString loc = reply->header(QNetworkRequest::LocationHeader).toString();
|
||||
@ -1490,20 +1490,19 @@ void WebLoadManager::onProgress(qint64 already, qint64 size) {
|
||||
}
|
||||
|
||||
void WebLoadManager::onMeta() {
|
||||
QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
|
||||
const auto reply = qobject_cast<QNetworkReply*>(QObject::sender());
|
||||
if (!reply) return;
|
||||
|
||||
Replies::iterator j = _replies.find(reply);
|
||||
const auto j = _replies.find(reply);
|
||||
if (j == _replies.cend()) { // handled already
|
||||
return;
|
||||
}
|
||||
webFileLoaderPrivate *loader = j.value();
|
||||
const auto loader = j.value();
|
||||
|
||||
typedef QList<QNetworkReply::RawHeaderPair> Pairs;
|
||||
Pairs pairs = reply->rawHeaderPairs();
|
||||
for (Pairs::iterator i = pairs.begin(), e = pairs.end(); i != e; ++i) {
|
||||
const auto pairs = reply->rawHeaderPairs();
|
||||
for (auto i = pairs.begin(), e = pairs.end(); i != e; ++i) {
|
||||
if (QString::fromUtf8(i->first).toLower() == "content-range") {
|
||||
QRegularExpressionMatch m = QRegularExpression(qsl("/(\\d+)([^\\d]|$)")).match(QString::fromUtf8(i->second));
|
||||
const auto m = QRegularExpression(qsl("/(\\d+)([^\\d]|$)")).match(QString::fromUtf8(i->second));
|
||||
if (m.hasMatch()) {
|
||||
loader->setProgress(qMax(qint64(loader->data().size()), loader->already()), m.captured(1).toLongLong());
|
||||
if (!handleReplyResult(loader, WebReplyProcessProgress)) {
|
||||
|
@ -17,7 +17,28 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
namespace Storage {
|
||||
namespace {
|
||||
|
||||
constexpr auto kMaxUploadFileParallelSize = MTP::kUploadSessionsCount * 512 * 1024; // max 512kb uploaded at the same time in each session
|
||||
// max 512kb uploaded at the same time in each session
|
||||
constexpr auto kMaxUploadFileParallelSize = MTP::kUploadSessionsCount * 512 * 1024;
|
||||
|
||||
constexpr auto kDocumentMaxPartsCount = 3000;
|
||||
|
||||
// 32kb for tiny document ( < 1mb )
|
||||
constexpr auto kDocumentUploadPartSize0 = 32 * 1024;
|
||||
|
||||
// 64kb for little document ( <= 32mb )
|
||||
constexpr auto kDocumentUploadPartSize1 = 64 * 1024;
|
||||
|
||||
// 128kb for small document ( <= 375mb )
|
||||
constexpr auto kDocumentUploadPartSize2 = 128 * 1024;
|
||||
|
||||
// 256kb for medium document ( <= 750mb )
|
||||
constexpr auto kDocumentUploadPartSize3 = 256 * 1024;
|
||||
|
||||
// 512kb for large document ( <= 1500mb )
|
||||
constexpr auto kDocumentUploadPartSize4 = 512 * 1024;
|
||||
|
||||
// One part each half second, if not uploaded faster.
|
||||
constexpr auto kUploadRequestInterval = TimeMs(500);
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -75,11 +96,11 @@ void Uploader::File::setDocSize(int32 size) {
|
||||
docSize = size;
|
||||
constexpr auto limit0 = 1024 * 1024;
|
||||
constexpr auto limit1 = 32 * limit0;
|
||||
if (docSize >= limit0 || !setPartSize(DocumentUploadPartSize0)) {
|
||||
if (docSize > limit1 || !setPartSize(DocumentUploadPartSize1)) {
|
||||
if (!setPartSize(DocumentUploadPartSize2)) {
|
||||
if (!setPartSize(DocumentUploadPartSize3)) {
|
||||
if (!setPartSize(DocumentUploadPartSize4)) {
|
||||
if (docSize >= limit0 || !setPartSize(kDocumentUploadPartSize0)) {
|
||||
if (docSize > limit1 || !setPartSize(kDocumentUploadPartSize1)) {
|
||||
if (!setPartSize(kDocumentUploadPartSize2)) {
|
||||
if (!setPartSize(kDocumentUploadPartSize3)) {
|
||||
if (!setPartSize(kDocumentUploadPartSize4)) {
|
||||
LOG(("Upload Error: bad doc size: %1").arg(docSize));
|
||||
}
|
||||
}
|
||||
@ -92,7 +113,7 @@ bool Uploader::File::setPartSize(uint32 partSize) {
|
||||
docPartSize = partSize;
|
||||
docPartsCount = (docSize / docPartSize)
|
||||
+ ((docSize % docPartSize) ? 1 : 0);
|
||||
return (docPartsCount <= DocumentMaxPartsCount);
|
||||
return (docPartsCount <= kDocumentMaxPartsCount);
|
||||
}
|
||||
|
||||
uint64 Uploader::File::id() const {
|
||||
@ -288,7 +309,7 @@ void Uploader::sendNext() {
|
||||
QByteArray docMd5(32, Qt::Uninitialized);
|
||||
hashMd5Hex(uploadingData.md5Hash.result(), docMd5.data());
|
||||
|
||||
const auto file = (uploadingData.docSize > UseBigFilesFrom)
|
||||
const auto file = (uploadingData.docSize > kUseBigFilesFrom)
|
||||
? MTP_inputFileBig(
|
||||
MTP_long(uploadingData.id()),
|
||||
MTP_int(uploadingData.docPartsCount),
|
||||
@ -347,7 +368,7 @@ void Uploader::sendNext() {
|
||||
}
|
||||
}
|
||||
toSend = uploadingData.docFile->read(uploadingData.docPartSize);
|
||||
if (uploadingData.docSize <= UseBigFilesFrom) {
|
||||
if (uploadingData.docSize <= kUseBigFilesFrom) {
|
||||
uploadingData.md5Hash.feed(toSend.constData(), toSend.size());
|
||||
}
|
||||
} else {
|
||||
@ -356,7 +377,7 @@ void Uploader::sendNext() {
|
||||
toSend = content.mid(offset, uploadingData.docPartSize);
|
||||
if ((uploadingData.type() == SendMediaType::File
|
||||
|| uploadingData.type() == SendMediaType::Audio)
|
||||
&& uploadingData.docSentParts <= UseBigFilesFrom) {
|
||||
&& uploadingData.docSentParts <= kUseBigFilesFrom) {
|
||||
uploadingData.md5Hash.feed(toSend.constData(), toSend.size());
|
||||
}
|
||||
}
|
||||
@ -367,7 +388,7 @@ void Uploader::sendNext() {
|
||||
return;
|
||||
}
|
||||
mtpRequestId requestId;
|
||||
if (uploadingData.docSize > UseBigFilesFrom) {
|
||||
if (uploadingData.docSize > kUseBigFilesFrom) {
|
||||
requestId = MTP::send(
|
||||
MTPupload_SaveBigFilePart(
|
||||
MTP_long(uploadingData.id()),
|
||||
@ -411,7 +432,7 @@ void Uploader::sendNext() {
|
||||
|
||||
parts.erase(part);
|
||||
}
|
||||
nextTimer.start(UploadRequestInterval);
|
||||
nextTimer.start(kUploadRequestInterval);
|
||||
}
|
||||
|
||||
void Uploader::cancel(const FullMsgId &msgId) {
|
||||
|
@ -12,6 +12,9 @@ struct SendMediaReady;
|
||||
|
||||
namespace Storage {
|
||||
|
||||
// MTP big files methods used for files greater than 10mb.
|
||||
constexpr auto kUseBigFilesFrom = 10 * 1024 * 1024;
|
||||
|
||||
struct UploadedPhoto {
|
||||
FullMsgId fullId;
|
||||
bool silent = false;
|
||||
|
@ -25,6 +25,9 @@ namespace {
|
||||
|
||||
constexpr auto kThumbnailQuality = 87;
|
||||
constexpr auto kThumbnailSize = 320;
|
||||
constexpr auto kPhotoUploadPartSize = 32 * 1024;
|
||||
|
||||
using Storage::ValidateThumbDimensions;
|
||||
|
||||
struct PreparedFileThumbnail {
|
||||
uint64 id = 0;
|
||||
@ -37,7 +40,7 @@ struct PreparedFileThumbnail {
|
||||
PreparedFileThumbnail PrepareFileThumbnail(QImage &&original) {
|
||||
const auto width = original.width();
|
||||
const auto height = original.height();
|
||||
if (!Storage::ValidateThumbDimensions(width, height)) {
|
||||
if (!ValidateThumbDimensions(width, height)) {
|
||||
return {};
|
||||
}
|
||||
auto result = PreparedFileThumbnail();
|
||||
@ -133,7 +136,43 @@ MTPInputSingleMedia PrepareAlbumItemMedia(
|
||||
|
||||
} // namespace
|
||||
|
||||
using Storage::ValidateThumbDimensions;
|
||||
SendMediaReady::SendMediaReady(
|
||||
SendMediaType type,
|
||||
const QString &file,
|
||||
const QString &filename,
|
||||
int32 filesize,
|
||||
const QByteArray &data,
|
||||
const uint64 &id,
|
||||
const uint64 &thumbId,
|
||||
const QString &thumbExt,
|
||||
const PeerId &peer,
|
||||
const MTPPhoto &photo,
|
||||
const PreparedPhotoThumbs &photoThumbs,
|
||||
const MTPDocument &document,
|
||||
const QByteArray &jpeg,
|
||||
MsgId replyTo)
|
||||
: replyTo(replyTo)
|
||||
, type(type)
|
||||
, file(file)
|
||||
, filename(filename)
|
||||
, filesize(filesize)
|
||||
, data(data)
|
||||
, thumbExt(thumbExt)
|
||||
, id(id)
|
||||
, thumbId(thumbId)
|
||||
, peer(peer)
|
||||
, photo(photo)
|
||||
, document(document)
|
||||
, photoThumbs(photoThumbs) {
|
||||
if (!jpeg.isEmpty()) {
|
||||
int32 size = jpeg.size();
|
||||
for (int32 i = 0, part = 0; i < size; i += kPhotoUploadPartSize, ++part) {
|
||||
parts.insert(part, jpeg.mid(i, kPhotoUploadPartSize));
|
||||
}
|
||||
jpeg_md5.resize(32);
|
||||
hashMd5Hex(jpeg.constData(), jpeg.size(), jpeg_md5.data());
|
||||
}
|
||||
}
|
||||
|
||||
SendMediaReady PreparePeerPhoto(PeerId peerId, QImage &&image) {
|
||||
PreparedPhotoThumbs photoThumbs;
|
||||
@ -290,10 +329,8 @@ void TaskQueue::stop() {
|
||||
_thread->quit();
|
||||
DEBUG_LOG(("Waiting for taskThread to finish"));
|
||||
_thread->wait();
|
||||
delete _worker;
|
||||
delete _thread;
|
||||
_worker = 0;
|
||||
_thread = 0;
|
||||
delete base::take(_worker);
|
||||
delete base::take(_thread);
|
||||
}
|
||||
_tasksToProcess.clear();
|
||||
_tasksToFinish.clear();
|
||||
@ -399,6 +436,31 @@ FileLoadResult::FileLoadResult(
|
||||
, caption(caption) {
|
||||
}
|
||||
|
||||
void FileLoadResult::setFileData(const QByteArray &filedata) {
|
||||
if (filedata.isEmpty()) {
|
||||
partssize = 0;
|
||||
} else {
|
||||
partssize = filedata.size();
|
||||
for (int32 i = 0, part = 0; i < partssize; i += kPhotoUploadPartSize, ++part) {
|
||||
fileparts.insert(part, filedata.mid(i, kPhotoUploadPartSize));
|
||||
}
|
||||
filemd5.resize(32);
|
||||
hashMd5Hex(filedata.constData(), filedata.size(), filemd5.data());
|
||||
}
|
||||
}
|
||||
|
||||
void FileLoadResult::setThumbData(const QByteArray &thumbdata) {
|
||||
if (!thumbdata.isEmpty()) {
|
||||
int32 size = thumbdata.size();
|
||||
for (int32 i = 0, part = 0; i < size; i += kPhotoUploadPartSize, ++part) {
|
||||
thumbparts.insert(part, thumbdata.mid(i, kPhotoUploadPartSize));
|
||||
}
|
||||
thumbmd5.resize(32);
|
||||
hashMd5Hex(thumbdata.constData(), thumbdata.size(), thumbmd5.data());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FileLoadTask::FileLoadTask(
|
||||
const QString &filepath,
|
||||
const QByteArray &content,
|
||||
|
@ -47,29 +47,22 @@ using SendMediaPrepareList = QList<SendMediaPrepare>;
|
||||
using UploadFileParts = QMap<int, QByteArray>;
|
||||
struct SendMediaReady {
|
||||
SendMediaReady() = default; // temp
|
||||
SendMediaReady(SendMediaType type, const QString &file, const QString &filename, int32 filesize, const QByteArray &data, const uint64 &id, const uint64 &thumbId, const QString &thumbExt, const PeerId &peer, const MTPPhoto &photo, const PreparedPhotoThumbs &photoThumbs, const MTPDocument &document, const QByteArray &jpeg, MsgId replyTo)
|
||||
: replyTo(replyTo)
|
||||
, type(type)
|
||||
, file(file)
|
||||
, filename(filename)
|
||||
, filesize(filesize)
|
||||
, data(data)
|
||||
, thumbExt(thumbExt)
|
||||
, id(id)
|
||||
, thumbId(thumbId)
|
||||
, peer(peer)
|
||||
, photo(photo)
|
||||
, document(document)
|
||||
, photoThumbs(photoThumbs) {
|
||||
if (!jpeg.isEmpty()) {
|
||||
int32 size = jpeg.size();
|
||||
for (int32 i = 0, part = 0; i < size; i += UploadPartSize, ++part) {
|
||||
parts.insert(part, jpeg.mid(i, UploadPartSize));
|
||||
}
|
||||
jpeg_md5.resize(32);
|
||||
hashMd5Hex(jpeg.constData(), jpeg.size(), jpeg_md5.data());
|
||||
}
|
||||
}
|
||||
SendMediaReady(
|
||||
SendMediaType type,
|
||||
const QString &file,
|
||||
const QString &filename,
|
||||
int32 filesize,
|
||||
const QByteArray &data,
|
||||
const uint64 &id,
|
||||
const uint64 &thumbId,
|
||||
const QString &thumbExt,
|
||||
const PeerId &peer,
|
||||
const MTPPhoto &photo,
|
||||
const PreparedPhotoThumbs &photoThumbs,
|
||||
const MTPDocument &document,
|
||||
const QByteArray &jpeg,
|
||||
MsgId replyTo);
|
||||
|
||||
MsgId replyTo;
|
||||
SendMediaType type;
|
||||
QString file, filename;
|
||||
@ -233,28 +226,9 @@ struct FileLoadResult {
|
||||
PreparedPhotoThumbs photoThumbs;
|
||||
TextWithTags caption;
|
||||
|
||||
void setFileData(const QByteArray &filedata) {
|
||||
if (filedata.isEmpty()) {
|
||||
partssize = 0;
|
||||
} else {
|
||||
partssize = filedata.size();
|
||||
for (int32 i = 0, part = 0; i < partssize; i += UploadPartSize, ++part) {
|
||||
fileparts.insert(part, filedata.mid(i, UploadPartSize));
|
||||
}
|
||||
filemd5.resize(32);
|
||||
hashMd5Hex(filedata.constData(), filedata.size(), filemd5.data());
|
||||
}
|
||||
}
|
||||
void setThumbData(const QByteArray &thumbdata) {
|
||||
if (!thumbdata.isEmpty()) {
|
||||
int32 size = thumbdata.size();
|
||||
for (int32 i = 0, part = 0; i < size; i += UploadPartSize, ++part) {
|
||||
thumbparts.insert(part, thumbdata.mid(i, UploadPartSize));
|
||||
}
|
||||
thumbmd5.resize(32);
|
||||
hashMd5Hex(thumbdata.constData(), thumbdata.size(), thumbmd5.data());
|
||||
}
|
||||
}
|
||||
void setFileData(const QByteArray &filedata);
|
||||
void setThumbData(const QByteArray &thumbdata);
|
||||
|
||||
};
|
||||
|
||||
struct FileMediaInformation {
|
||||
|
@ -1283,7 +1283,7 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
|
||||
} else {
|
||||
Global::SetProxiesList({});
|
||||
}
|
||||
Sandbox::refreshGlobalProxy();
|
||||
Core::App().refreshGlobalProxy();
|
||||
} break;
|
||||
|
||||
case dbiConnectionType: {
|
||||
@ -1383,7 +1383,7 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
|
||||
Global::SetProxySettings(ProxyData::Settings::System);
|
||||
}
|
||||
}
|
||||
Sandbox::refreshGlobalProxy();
|
||||
Core::App().refreshGlobalProxy();
|
||||
} break;
|
||||
|
||||
case dbiThemeKeyOld: {
|
||||
|
@ -20,8 +20,8 @@ NeverFreedPointer<QMap<QObject*, Manager*>> _managers;
|
||||
|
||||
} // namespace
|
||||
|
||||
Manager::Manager(QWidget *parent) : QObject(parent) {
|
||||
connect(&_hideTimer, SIGNAL(timeout()), this, SLOT(onHideTimeout()));
|
||||
Manager::Manager(QWidget *parent) : QObject(parent)
|
||||
, _hideTimer([=] { hideByTimer(); }) {
|
||||
}
|
||||
|
||||
bool Manager::eventFilter(QObject *o, QEvent *e) {
|
||||
@ -80,7 +80,7 @@ void Manager::addToast(std::unique_ptr<Instance> &&toast) {
|
||||
}
|
||||
}
|
||||
|
||||
void Manager::onHideTimeout() {
|
||||
void Manager::hideByTimer() {
|
||||
auto now = getms(true);
|
||||
for (auto i = _toastByHideTime.begin(); i != _toastByHideTime.cend();) {
|
||||
if (i.key() <= now) {
|
||||
@ -114,9 +114,11 @@ void Manager::startNextHideTimer() {
|
||||
|
||||
auto ms = getms(true);
|
||||
if (ms >= _toastByHideTime.firstKey()) {
|
||||
QMetaObject::invokeMethod(this, SLOT("onHideTimeout"), Qt::QueuedConnection);
|
||||
crl::on_main(this, [=] {
|
||||
hideByTimer();
|
||||
});
|
||||
} else {
|
||||
_hideTimer.start(_toastByHideTime.firstKey() - ms);
|
||||
_hideTimer.callOnce(_toastByHideTime.firstKey() - ms);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#pragma once
|
||||
|
||||
#include "ui/toast/toast.h"
|
||||
#include "core/single_timer.h"
|
||||
#include "base/timer.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Toast {
|
||||
@ -32,14 +32,14 @@ protected:
|
||||
bool eventFilter(QObject *o, QEvent *e);
|
||||
|
||||
private slots:
|
||||
void onHideTimeout();
|
||||
void onToastWidgetDestroyed(QObject *widget);
|
||||
|
||||
private:
|
||||
Manager(QWidget *parent);
|
||||
void startNextHideTimer();
|
||||
void hideByTimer();
|
||||
|
||||
SingleTimer _hideTimer;
|
||||
base::Timer _hideTimer;
|
||||
TimeMs _nextHide = 0;
|
||||
|
||||
QMultiMap<TimeMs, Instance*> _toastByHideTime;
|
||||
|
@ -234,8 +234,7 @@ void ForceFullRepaint(not_null<QWidget*> widget) {
|
||||
}
|
||||
|
||||
void PostponeCall(FnMut<void()> &&callable) {
|
||||
const auto application = static_cast<Application*>(qApp);
|
||||
application->postponeCall(std::move(callable));
|
||||
Core::App().postponeCall(std::move(callable));
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
@ -341,6 +341,7 @@ private:
|
||||
};
|
||||
|
||||
class TWidget : public TWidgetHelper<QWidget> {
|
||||
// The Q_OBJECT meta info is used for qobject_cast!
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "ui/widgets/continuous_sliders.h"
|
||||
|
||||
#include "base/timer.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace {
|
||||
|
||||
@ -29,14 +31,13 @@ void ContinuousSlider::setDisabled(bool disabled) {
|
||||
void ContinuousSlider::setMoveByWheel(bool move) {
|
||||
if (move != moveByWheel()) {
|
||||
if (move) {
|
||||
_byWheelFinished = std::make_unique<SingleTimer>();
|
||||
_byWheelFinished->setTimeoutHandler([this] {
|
||||
_byWheelFinished = std::make_unique<base::Timer>([=] {
|
||||
if (_changeFinishedCallback) {
|
||||
_changeFinishedCallback(getCurrentValue());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
_byWheelFinished.reset();
|
||||
_byWheelFinished = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -109,7 +110,7 @@ void ContinuousSlider::wheelEvent(QWheelEvent *e) {
|
||||
if (_changeProgressCallback) {
|
||||
_changeProgressCallback(finalValue);
|
||||
}
|
||||
_byWheelFinished->start(kByWheelFinishedTimeout);
|
||||
_byWheelFinished->callOnce(kByWheelFinishedTimeout);
|
||||
}
|
||||
|
||||
void ContinuousSlider::updateDownValueFromPos(const QPoint &pos) {
|
||||
|
@ -10,6 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "styles/style_widgets.h"
|
||||
#include "ui/rp_widget.h"
|
||||
|
||||
namespace base {
|
||||
class Timer;
|
||||
} // namespace base
|
||||
|
||||
namespace Ui {
|
||||
|
||||
class ContinuousSlider : public RpWidget {
|
||||
@ -87,7 +91,7 @@ private:
|
||||
Direction _direction = Direction::Horizontal;
|
||||
bool _disabled = false;
|
||||
|
||||
std::unique_ptr<SingleTimer> _byWheelFinished;
|
||||
std::unique_ptr<base::Timer> _byWheelFinished;
|
||||
|
||||
Fn<float64(float64)> _adjustCallback;
|
||||
Fn<void(float64)> _changeProgressCallback;
|
||||
|
@ -231,7 +231,7 @@ void DropdownMenu::hideFinish() {
|
||||
//
|
||||
// auto menuTopLeft = mapFromGlobal(_menu->mapToGlobal(QPoint(0, 0)));
|
||||
// auto w = p - QPoint(0, menuTopLeft.y());
|
||||
// auto r = Sandbox::screenGeometry(p);
|
||||
// auto r = QApplication::desktop()->screenGeometry(p);
|
||||
// if (rtl()) {
|
||||
// if (w.x() - width() < r.x() - _padding.left()) {
|
||||
// if (_parent && w.x() + _parent->width() - _padding.left() - _padding.right() + width() - _padding.right() <= r.x() + r.width()) {
|
||||
|
@ -528,12 +528,12 @@ public:
|
||||
setParent(QCoreApplication::instance());
|
||||
}
|
||||
|
||||
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = 0) const {
|
||||
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const override {
|
||||
}
|
||||
QRect subElementRect(SubElement r, const QStyleOption *opt, const QWidget *widget = 0) const {
|
||||
QRect subElementRect(SubElement r, const QStyleOption *opt, const QWidget *widget = nullptr) const override {
|
||||
switch (r) {
|
||||
case SE_LineEditContents:
|
||||
const InputClass *w = widget ? qobject_cast<const InputClass*>(widget) : 0;
|
||||
const auto w = widget ? qobject_cast<const InputClass*>(widget) : nullptr;
|
||||
return w ? w->getTextRect() : QCommonStyle::subElementRect(r, opt, widget);
|
||||
break;
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ enum class InputSubmitSettings {
|
||||
};
|
||||
|
||||
class FlatInput : public TWidgetHelper<QLineEdit>, private base::Subscriber {
|
||||
// The Q_OBJECT meta info is used for qobject_cast!
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
@ -493,6 +494,7 @@ private:
|
||||
class MaskedInputField
|
||||
: public RpWidgetWrap<QLineEdit>
|
||||
, private base::Subscriber {
|
||||
// The Q_OBJECT meta info is used for qobject_cast!
|
||||
Q_OBJECT
|
||||
|
||||
using Parent = RpWidgetWrap<QLineEdit>;
|
||||
|
@ -447,7 +447,7 @@ void PopupMenu::showMenu(const QPoint &p, PopupMenu *parent, TriggeredSource sou
|
||||
|
||||
auto origin = PanelAnimation::Origin::TopLeft;
|
||||
auto w = p - QPoint(0, _padding.top());
|
||||
auto r = Sandbox::screenGeometry(p);
|
||||
auto r = QApplication::desktop()->screenGeometry(p);
|
||||
_useTransparency = Platform::TranslucentWindowsSupported(p);
|
||||
setAttribute(Qt::WA_OpaquePaintEvent, !_useTransparency);
|
||||
handleCompositingUpdate();
|
||||
|
@ -636,7 +636,7 @@ void ScrollArea::resizeEvent(QResizeEvent *e) {
|
||||
_verticalBar->recountSize();
|
||||
_topShadow->setGeometry(QRect(0, 0, width(), qAbs(_st.topsh)));
|
||||
_bottomShadow->setGeometry(QRect(0, height() - qAbs(_st.bottomsh), width(), qAbs(_st.bottomsh)));
|
||||
if (SplittedWidget *w = qobject_cast<SplittedWidget*>(widget())) {
|
||||
if (const auto w = qobject_cast<SplittedWidget*>(widget())) {
|
||||
w->resize(width() - w->otherWidth(), w->height());
|
||||
if (!rtl()) {
|
||||
_other->move(w->width(), w->y());
|
||||
@ -720,7 +720,7 @@ void ScrollArea::scrollToY(int toTop, int toBottom) {
|
||||
}
|
||||
|
||||
void ScrollArea::doSetOwnedWidget(object_ptr<TWidget> w) {
|
||||
auto splitted = qobject_cast<SplittedWidget*>(w.data());
|
||||
const auto splitted = qobject_cast<SplittedWidget*>(w.data());
|
||||
if (widget() && _touchEnabled) {
|
||||
widget()->removeEventFilter(this);
|
||||
if (!_widgetAcceptsTouch) widget()->setAttribute(Qt::WA_AcceptTouchEvents, false);
|
||||
|
@ -110,6 +110,7 @@ private:
|
||||
};
|
||||
|
||||
class SplittedWidget : public Ui::RpWidget {
|
||||
// The Q_OBJECT meta info is used for qobject_cast!
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -33,14 +33,12 @@ constexpr auto kMinimalAlertDelay = TimeMs(500);
|
||||
|
||||
} // namespace
|
||||
|
||||
System::System(AuthSession *session) : _authSession(session) {
|
||||
System::System(AuthSession *session)
|
||||
: _authSession(session)
|
||||
, _waitTimer([=] { showNext(); }) {
|
||||
createManager();
|
||||
|
||||
_waitTimer.setTimeoutHandler([this] {
|
||||
showNext();
|
||||
});
|
||||
|
||||
subscribe(settingsChanged(), [this](ChangeType type) {
|
||||
subscribe(settingsChanged(), [=](ChangeType type) {
|
||||
if (type == ChangeType::DesktopEnabled) {
|
||||
App::wnd()->updateTrayMenu();
|
||||
clearAll();
|
||||
@ -124,7 +122,7 @@ void System::schedule(History *history, HistoryItem *item) {
|
||||
}
|
||||
if (haveSetting) {
|
||||
if (!_waitTimer.isActive() || _waitTimer.remainingTime() > delay) {
|
||||
_waitTimer.start(delay);
|
||||
_waitTimer.callOnce(delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -150,7 +148,7 @@ void System::clearFromHistory(History *history) {
|
||||
_waiters.remove(history);
|
||||
_settingWaiters.remove(history);
|
||||
|
||||
_waitTimer.stop();
|
||||
_waitTimer.cancel();
|
||||
showNext();
|
||||
}
|
||||
|
||||
@ -209,7 +207,7 @@ void System::checkDelayed() {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
_waitTimer.stop();
|
||||
_waitTimer.cancel();
|
||||
showNext();
|
||||
}
|
||||
|
||||
@ -259,7 +257,7 @@ void System::showNext() {
|
||||
|
||||
if (_waiters.isEmpty() || !Global::DesktopNotify() || Platform::Notifications::SkipToast()) {
|
||||
if (nextAlert) {
|
||||
_waitTimer.start(nextAlert - ms);
|
||||
_waitTimer.callOnce(nextAlert - ms);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -306,7 +304,7 @@ void System::showNext() {
|
||||
next = nextAlert;
|
||||
nextAlert = 0;
|
||||
}
|
||||
_waitTimer.start(next - ms);
|
||||
_waitTimer.callOnce(next - ms);
|
||||
break;
|
||||
} else {
|
||||
auto forwardedItem = notifyItem->Has<HistoryMessageForwarded>() ? notifyItem : nullptr; // forwarded notify grouping
|
||||
@ -366,7 +364,7 @@ void System::showNext() {
|
||||
}
|
||||
}
|
||||
if (nextAlert) {
|
||||
_waitTimer.start(nextAlert - ms);
|
||||
_waitTimer.callOnce(nextAlert - ms);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "base/timer.h"
|
||||
|
||||
class AuthSession;
|
||||
|
||||
namespace Platform {
|
||||
@ -96,7 +98,7 @@ private:
|
||||
using Waiters = QMap<History*, Waiter>;
|
||||
Waiters _waiters;
|
||||
Waiters _settingWaiters;
|
||||
SingleTimer _waitTimer;
|
||||
base::Timer _waitTimer;
|
||||
|
||||
QMap<History*, QMap<TimeMs, PeerData*>> _whenAlerts;
|
||||
|
||||
|
@ -53,7 +53,9 @@ std::unique_ptr<Manager> Create(System *system) {
|
||||
return std::make_unique<Manager>(system);
|
||||
}
|
||||
|
||||
Manager::Manager(System *system) : Notifications::Manager(system) {
|
||||
Manager::Manager(System *system)
|
||||
: Notifications::Manager(system)
|
||||
, _inputCheckTimer([=] { checkLastInput(); }) {
|
||||
subscribe(system->authSession()->downloader().taskFinished(), [this] {
|
||||
for_const (auto ¬ification, _notifications) {
|
||||
notification->updatePeerPhoto();
|
||||
@ -62,7 +64,6 @@ Manager::Manager(System *system) : Notifications::Manager(system) {
|
||||
subscribe(system->settingsChanged(), [this](ChangeType change) {
|
||||
settingsChanged(change);
|
||||
});
|
||||
_inputCheckTimer.setTimeoutHandler([this] { checkLastInput(); });
|
||||
}
|
||||
|
||||
Manager::QueuedNotification::QueuedNotification(
|
||||
@ -144,7 +145,7 @@ void Manager::checkLastInput() {
|
||||
}
|
||||
}
|
||||
if (waiting) {
|
||||
_inputCheckTimer.start(300);
|
||||
_inputCheckTimer.callOnce(300);
|
||||
}
|
||||
}
|
||||
|
||||
@ -494,15 +495,25 @@ void Background::paintEvent(QPaintEvent *e) {
|
||||
p.fillRect(st::notifyBorderWidth, height() - st::notifyBorderWidth, width() - 2 * st::notifyBorderWidth, st::notifyBorderWidth, st::notifyBorder);
|
||||
}
|
||||
|
||||
Notification::Notification(Manager *manager, History *history, PeerData *peer, PeerData *author, HistoryItem *msg, int forwardedCount, QPoint startPosition, int shift, Direction shiftDirection) : Widget(manager, startPosition, shift, shiftDirection)
|
||||
Notification::Notification(
|
||||
Manager *manager,
|
||||
History *history,
|
||||
PeerData *peer,
|
||||
PeerData *author,
|
||||
HistoryItem *msg,
|
||||
int forwardedCount,
|
||||
QPoint startPosition,
|
||||
int shift,
|
||||
Direction shiftDirection)
|
||||
: Widget(manager, startPosition, shift, shiftDirection)
|
||||
#ifdef Q_OS_WIN
|
||||
, _started(GetTickCount())
|
||||
#endif // Q_OS_WIN
|
||||
, _history(history)
|
||||
, _peer(peer)
|
||||
, _author(author)
|
||||
, _item(msg)
|
||||
, _forwardedCount(forwardedCount)
|
||||
#ifdef Q_OS_WIN
|
||||
, _started(GetTickCount())
|
||||
#endif // Q_OS_WIN
|
||||
, _close(this, st::notifyClose)
|
||||
, _reply(this, langFactory(lng_notification_reply), st::defaultBoxButton) {
|
||||
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
|
||||
|
@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#pragma once
|
||||
|
||||
#include "window/notifications_manager.h"
|
||||
#include "core/single_timer.h"
|
||||
#include "base/timer.h"
|
||||
|
||||
namespace Ui {
|
||||
class IconButton;
|
||||
@ -79,7 +79,7 @@ private:
|
||||
std::unique_ptr<HideAllButton> _hideAll;
|
||||
|
||||
bool _positionsOutdated = false;
|
||||
SingleTimer _inputCheckTimer;
|
||||
base::Timer _inputCheckTimer;
|
||||
|
||||
struct QueuedNotification {
|
||||
QueuedNotification(not_null<HistoryItem*> item, int forwardedCount);
|
||||
|
@ -21,8 +21,9 @@ constexpr int kNotifyDeletePhotoAfterMs = 60000;
|
||||
|
||||
} // namespace
|
||||
|
||||
CachedUserpics::CachedUserpics(Type type) : _type(type) {
|
||||
connect(&_clearTimer, SIGNAL(timeout()), this, SLOT(onClear()));
|
||||
CachedUserpics::CachedUserpics(Type type)
|
||||
: _type(type)
|
||||
, _clearTimer([=] { onClear(); }) {
|
||||
QDir().mkpath(cWorkingDir() + qsl("tdata/temp"));
|
||||
}
|
||||
|
||||
@ -87,7 +88,7 @@ void CachedUserpics::clearInMs(int ms) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
_clearTimer.start(ms);
|
||||
_clearTimer.callOnce(ms);
|
||||
}
|
||||
|
||||
void CachedUserpics::onClear() {
|
||||
|
@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#pragma once
|
||||
|
||||
#include "window/notifications_manager.h"
|
||||
#include "core/single_timer.h"
|
||||
#include "base/timer.h"
|
||||
|
||||
namespace Window {
|
||||
namespace Notifications {
|
||||
@ -42,7 +42,7 @@ private:
|
||||
using Images = QMap<StorageKey, Image>;
|
||||
Images _images;
|
||||
bool _someSavedFlag = false;
|
||||
SingleTimer _clearTimer;
|
||||
base::Timer _clearTimer;
|
||||
|
||||
};
|
||||
|
||||
|
@ -21,13 +21,14 @@ constexpr int kWaitBeforeRevertMs = 15999;
|
||||
|
||||
} // namespace
|
||||
|
||||
WarningWidget::WarningWidget(QWidget *parent) : TWidget(parent)
|
||||
WarningWidget::WarningWidget(QWidget *parent)
|
||||
: TWidget(parent)
|
||||
, _timer([=] { handleTimer(); })
|
||||
, _secondsLeft(kWaitBeforeRevertMs / 1000)
|
||||
, _keepChanges(this, langFactory(lng_theme_keep_changes), st::defaultBoxButton)
|
||||
, _revert(this, langFactory(lng_theme_revert), st::defaultBoxButton) {
|
||||
_keepChanges->setClickedCallback([] { Window::Theme::KeepApplied(); });
|
||||
_revert->setClickedCallback([] { Window::Theme::Revert(); });
|
||||
_timer.setTimeoutHandler([this] { handleTimer(); });
|
||||
updateText();
|
||||
}
|
||||
|
||||
@ -52,7 +53,7 @@ void WarningWidget::paintEvent(QPaintEvent *e) {
|
||||
_cache = QPixmap();
|
||||
showChildren();
|
||||
_started = getms(true);
|
||||
_timer.start(100);
|
||||
_timer.callOnce(100);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -100,7 +101,7 @@ void WarningWidget::setSecondsLeft(int secondsLeft) {
|
||||
updateText();
|
||||
update();
|
||||
}
|
||||
_timer.start(100);
|
||||
_timer.callOnce(100);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +120,7 @@ void WarningWidget::hideAnimated() {
|
||||
}
|
||||
|
||||
void WarningWidget::startAnimation(bool hiding) {
|
||||
_timer.stop();
|
||||
_timer.cancel();
|
||||
_hiding = hiding;
|
||||
if (_cache.isNull()) {
|
||||
showChildren();
|
||||
|
@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "base/timer.h"
|
||||
|
||||
namespace Ui {
|
||||
class RoundButton;
|
||||
} // namespace Ui
|
||||
@ -43,7 +45,7 @@ private:
|
||||
QPixmap _cache;
|
||||
QRect _inner, _outer;
|
||||
|
||||
SingleTimer _timer;
|
||||
base::Timer _timer;
|
||||
TimeMs _started = 0;
|
||||
int _secondsLeft = 0;
|
||||
QString _text;
|
||||
|
@ -30,6 +30,7 @@
|
||||
'/MP', # Enable multi process build.
|
||||
'/EHsc', # Catch C++ exceptions only, extern C functions never throw a C++ exception.
|
||||
'/w14834', # [[nodiscard]]
|
||||
'/w15038', # wrong initialization order
|
||||
],
|
||||
'TreatWChar_tAsBuiltInType': 'false',
|
||||
},
|
||||
|
@ -140,8 +140,6 @@
|
||||
<(src_loc)/core/mime_type.h
|
||||
<(src_loc)/core/shortcuts.cpp
|
||||
<(src_loc)/core/shortcuts.h
|
||||
<(src_loc)/core/single_timer.cpp
|
||||
<(src_loc)/core/single_timer.h
|
||||
<(src_loc)/core/update_checker.cpp
|
||||
<(src_loc)/core/update_checker.h
|
||||
<(src_loc)/core/utils.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user