2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
class UpdateChecker;
|
|
|
|
class Application : public QApplication {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2014-06-14 19:32:11 +00:00
|
|
|
Application(int &argc, char **argv);
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2016-09-15 10:50:43 +00:00
|
|
|
bool event(QEvent *e) override;
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void createMessenger();
|
|
|
|
|
|
|
|
~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()
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
private:
|
|
|
|
typedef QPair<QLocalSocket*, QByteArray> LocalClient;
|
|
|
|
typedef QList<LocalClient> LocalClients;
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
|
|
|
|
// Autoupdating
|
|
|
|
public:
|
|
|
|
void startUpdateCheck(bool forceWait);
|
|
|
|
void stopUpdate();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
enum UpdatingState {
|
|
|
|
UpdatingNone,
|
|
|
|
UpdatingDownload,
|
|
|
|
UpdatingReady,
|
|
|
|
};
|
|
|
|
UpdatingState updatingState();
|
|
|
|
int32 updatingSize();
|
|
|
|
int32 updatingReady();
|
2016-01-11 15:43:29 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void updateChecking();
|
|
|
|
void updateLatest();
|
|
|
|
void updateProgress(qint64 ready, qint64 total);
|
|
|
|
void updateReady();
|
|
|
|
void updateFailed();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void updateCheck();
|
|
|
|
|
|
|
|
void updateGotCurrent();
|
|
|
|
void updateFailedCurrent(QNetworkReply::NetworkError e);
|
|
|
|
|
|
|
|
void onUpdateReady();
|
|
|
|
void onUpdateFailed();
|
|
|
|
|
|
|
|
private:
|
2017-02-23 10:59:19 +00:00
|
|
|
object_ptr<SingleTimer> _updateCheckTimer = { nullptr };
|
2016-04-14 19:24:42 +00:00
|
|
|
QNetworkReply *_updateReply = nullptr;
|
2016-01-11 15:43:29 +00:00
|
|
|
QNetworkAccessManager _updateManager;
|
2016-04-14 19:24:42 +00:00
|
|
|
QThread *_updateThread = nullptr;
|
|
|
|
UpdateChecker *_updateChecker = nullptr;
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
|
2016-01-11 15:43:29 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void startUpdateCheck();
|
|
|
|
void stopUpdate();
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
Application::UpdatingState updatingState();
|
|
|
|
int32 updatingSize();
|
|
|
|
int32 updatingReady();
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void updateChecking();
|
|
|
|
void updateLatest();
|
|
|
|
void updateProgress(qint64 ready, qint64 total);
|
|
|
|
void updateFailed();
|
|
|
|
void updateReady();
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
|
2016-01-11 15:43:29 +00:00
|
|
|
|
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
|