2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
namespace Core {
|
|
|
|
class Launcher;
|
2018-04-26 16:14:21 +00:00
|
|
|
class UpdateChecker;
|
2017-12-11 14:45:29 +00:00
|
|
|
} // namespace Core
|
|
|
|
|
2018-07-31 17:56:54 +00:00
|
|
|
bool InternalPassportLink(const QString &url);
|
2018-04-13 05:11:53 +00:00
|
|
|
bool StartUrlRequiresActivate(const QString &url);
|
|
|
|
|
2018-12-12 08:59:51 +00:00
|
|
|
class Application : public QApplication, private QAbstractNativeEventFilter {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-12-11 14:45:29 +00:00
|
|
|
Application(not_null<Core::Launcher*> launcher, int &argc, char **argv);
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2018-12-26 09:02:43 +00:00
|
|
|
int execute();
|
2016-09-15 10:50:43 +00:00
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void createMessenger();
|
2018-04-23 10:24:03 +00:00
|
|
|
void refreshGlobalProxy();
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2018-12-12 08:59:51 +00:00
|
|
|
void postponeCall(FnMut<void()> &&callable);
|
|
|
|
bool notify(QObject *receiver, QEvent *e) override;
|
2018-12-27 09:34:12 +00:00
|
|
|
void registerEnterFromEventLoop();
|
|
|
|
auto createEventNestingLevel() {
|
|
|
|
incrementEventNestingLevel();
|
|
|
|
return gsl::finally([=] { decrementEventNestingLevel(); });
|
|
|
|
}
|
2018-12-12 08:59:51 +00:00
|
|
|
|
2018-12-26 09:54:49 +00:00
|
|
|
void activateWindowDelayed(not_null<QWidget*> widget);
|
|
|
|
void pauseDelayedWindowActivations();
|
|
|
|
void resumeDelayedWindowActivations();
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
~Application();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void adjustSingleTimers();
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
// Single instance application
|
|
|
|
public slots:
|
|
|
|
void socketConnected();
|
|
|
|
void socketError(QLocalSocket::LocalSocketError e);
|
|
|
|
void socketDisconnected();
|
|
|
|
void socketWritten(qint64 bytes);
|
|
|
|
void socketReading();
|
|
|
|
void newInstanceConnected();
|
|
|
|
|
|
|
|
void readClients();
|
|
|
|
void removeClients();
|
|
|
|
|
2016-02-29 16:53:26 +00:00
|
|
|
void startApplication(); // will be done in exec()
|
|
|
|
void closeApplication(); // will be done in aboutToQuit()
|
|
|
|
|
2018-12-26 09:02:43 +00:00
|
|
|
protected:
|
|
|
|
bool event(QEvent *e) override;
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
private:
|
|
|
|
typedef QPair<QLocalSocket*, QByteArray> LocalClient;
|
|
|
|
typedef QList<LocalClient> LocalClients;
|
|
|
|
|
2018-12-12 08:59:51 +00:00
|
|
|
struct PostponedCall {
|
|
|
|
int loopNestingLevel = 0;
|
|
|
|
FnMut<void()> callable;
|
|
|
|
};
|
|
|
|
|
2018-12-27 09:34:12 +00:00
|
|
|
void incrementEventNestingLevel();
|
|
|
|
void decrementEventNestingLevel();
|
2018-12-12 08:59:51 +00:00
|
|
|
bool nativeEventFilter(
|
|
|
|
const QByteArray &eventType,
|
|
|
|
void *message,
|
|
|
|
long *result) override;
|
|
|
|
void processPostponedCalls(int level);
|
|
|
|
|
|
|
|
const Qt::HANDLE _mainThreadId = nullptr;
|
|
|
|
int _eventNestingLevel = 0;
|
|
|
|
int _loopNestingLevel = 0;
|
|
|
|
std::vector<int> _previousLoopNestingLevels;
|
|
|
|
std::vector<PostponedCall> _postponedCalls;
|
|
|
|
|
2018-12-26 09:54:49 +00:00
|
|
|
QPointer<QWidget> _windowForDelayedActivation;
|
|
|
|
bool _delayedActivationsPaused = false;
|
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
not_null<Core::Launcher*> _launcher;
|
2017-02-23 10:59:19 +00:00
|
|
|
std::unique_ptr<Messenger> _messengerInstance;
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
QString _localServerName, _localSocketReadData;
|
|
|
|
QLocalServer _localServer;
|
|
|
|
QLocalSocket _localSocket;
|
|
|
|
LocalClients _localClients;
|
2016-04-14 19:24:42 +00:00
|
|
|
bool _secondInstance = false;
|
2016-01-11 15:43:29 +00:00
|
|
|
|
|
|
|
void singleInstanceChecked();
|
|
|
|
|
|
|
|
private:
|
2018-04-26 16:14:21 +00:00
|
|
|
std::unique_ptr<Core::UpdateChecker> _updateChecker;
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
};
|
|
|
|
|
2018-12-26 09:54:49 +00:00
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
inline Application &App() {
|
|
|
|
Expects(QCoreApplication::instance() != nullptr);
|
|
|
|
|
|
|
|
return *static_cast<Application*>(QCoreApplication::instance());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Core
|
|
|
|
|
2016-02-08 14:54:55 +00:00
|
|
|
namespace Sandbox {
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
QRect availableGeometry();
|
|
|
|
QRect screenGeometry(const QPoint &p);
|
|
|
|
void setActiveWindow(QWidget *window);
|
|
|
|
bool isSavingSession();
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void execExternal(const QString &cmd);
|
2016-02-07 15:38:49 +00:00
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void adjustSingleTimers();
|
2016-01-30 16:31:10 +00:00
|
|
|
|
2018-04-23 10:24:03 +00:00
|
|
|
void refreshGlobalProxy();
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void connect(const char *signal, QObject *object, const char *method);
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void launch();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
} // namespace Sandbox
|