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-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "pspecific.h"
|
2016-10-05 16:56:27 +00:00
|
|
|
#include "core/single_timer.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
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;
|
|
|
|
|
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-12-23 13:21:01 +00:00
|
|
|
void onMainThreadTask();
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
private:
|
|
|
|
typedef QPair<QLocalSocket*, QByteArray> LocalClient;
|
|
|
|
typedef QList<LocalClient> LocalClients;
|
|
|
|
|
|
|
|
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:
|
|
|
|
SingleTimer _updateCheckTimer;
|
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
|
|
|
|
|
|
|
QRect availableGeometry();
|
|
|
|
QRect screenGeometry(const QPoint &p);
|
|
|
|
void setActiveWindow(QWidget *window);
|
|
|
|
bool isSavingSession();
|
|
|
|
|
2016-02-07 15:38:49 +00:00
|
|
|
void installEventFilter(QObject *filter);
|
2016-07-11 18:05:46 +00:00
|
|
|
void removeEventFilter(QObject *filter);
|
2016-02-07 15:38:49 +00:00
|
|
|
|
2016-01-30 16:31:10 +00:00
|
|
|
void execExternal(const QString &cmd);
|
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
|
|
|
|
void startUpdateCheck();
|
2015-10-15 10:18:24 +00:00
|
|
|
void stopUpdate();
|
2016-01-11 15:43:29 +00:00
|
|
|
|
|
|
|
Application::UpdatingState updatingState();
|
|
|
|
int32 updatingSize();
|
|
|
|
int32 updatingReady();
|
|
|
|
|
|
|
|
void updateChecking();
|
|
|
|
void updateLatest();
|
|
|
|
void updateProgress(qint64 ready, qint64 total);
|
|
|
|
void updateFailed();
|
|
|
|
void updateReady();
|
|
|
|
|
2016-10-18 07:56:38 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2016-02-05 19:53:01 +00:00
|
|
|
void connect(const char *signal, QObject *object, const char *method);
|
|
|
|
|
2016-02-08 14:54:55 +00:00
|
|
|
void launch();
|
2016-02-05 19:53:01 +00:00
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MainWidget;
|
|
|
|
class FileUploader;
|
|
|
|
class Translator;
|
|
|
|
|
|
|
|
class AppClass : public QObject, public RPCSender {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
AppClass();
|
|
|
|
~AppClass();
|
|
|
|
|
|
|
|
static AppClass *app();
|
2016-04-12 21:31:28 +00:00
|
|
|
static MainWindow *wnd();
|
2016-01-11 15:43:29 +00:00
|
|
|
static MainWidget *main();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
FileUploader *uploader();
|
|
|
|
void uploadProfilePhoto(const QImage &tosend, const PeerId &peerId);
|
2015-09-03 10:48:40 +00:00
|
|
|
void regPhotoUpdate(const PeerId &peer, const FullMsgId &msgId);
|
2014-05-30 08:53:19 +00:00
|
|
|
bool isPhotoUpdating(const PeerId &peer);
|
|
|
|
void cancelPhotoUpdate(const PeerId &peer);
|
|
|
|
|
|
|
|
void selfPhotoCleared(const MTPUserProfilePhoto &result);
|
2015-04-02 10:33:19 +00:00
|
|
|
void chatPhotoCleared(PeerId peer, const MTPUpdates &updates);
|
2014-05-30 08:53:19 +00:00
|
|
|
void selfPhotoDone(const MTPphotos_Photo &result);
|
2015-04-02 10:33:19 +00:00
|
|
|
void chatPhotoDone(PeerId peerId, const MTPUpdates &updates);
|
2014-05-30 08:53:19 +00:00
|
|
|
bool peerPhotoFail(PeerId peerId, const RPCError &e);
|
|
|
|
void peerClearPhoto(PeerId peer);
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void writeUserConfigIn(TimeMs ms);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2014-10-30 16:23:44 +00:00
|
|
|
void killDownloadSessionsStart(int32 dc);
|
|
|
|
void killDownloadSessionsStop(int32 dc);
|
|
|
|
|
2014-11-12 20:30:26 +00:00
|
|
|
void checkLocalTime();
|
2015-03-02 12:34:16 +00:00
|
|
|
void checkMapVersion();
|
2014-11-12 20:30:26 +00:00
|
|
|
|
2016-01-11 15:43:29 +00:00
|
|
|
signals:
|
2015-06-03 18:13:01 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void peerPhotoDone(PeerId peer);
|
|
|
|
void peerPhotoFail(PeerId peer);
|
|
|
|
|
2014-11-22 09:45:04 +00:00
|
|
|
void adjustSingleTimers();
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
public slots:
|
2016-02-26 09:29:07 +00:00
|
|
|
void photoUpdated(const FullMsgId &msgId, bool silent, const MTPInputFile &file);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
void onSwitchDebugMode();
|
2016-04-11 10:59:01 +00:00
|
|
|
void onSwitchWorkMode();
|
2015-04-02 10:33:19 +00:00
|
|
|
void onSwitchTestMode();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2014-10-30 16:23:44 +00:00
|
|
|
void killDownloadSessions();
|
2014-11-12 20:30:26 +00:00
|
|
|
void onAppStateChanged(Qt::ApplicationState state);
|
2014-10-30 16:23:44 +00:00
|
|
|
|
2016-03-19 16:55:15 +00:00
|
|
|
void call_handleHistoryUpdate();
|
2016-04-14 19:24:42 +00:00
|
|
|
void call_handleUnreadCounterUpdate();
|
2016-05-25 17:59:21 +00:00
|
|
|
void call_handleFileDialogQueue();
|
2016-06-02 13:02:55 +00:00
|
|
|
void call_handleDelayedPeerUpdates();
|
2016-08-18 19:27:43 +00:00
|
|
|
void call_handleObservables();
|
2016-03-19 16:55:15 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
private:
|
2016-10-28 12:44:28 +00:00
|
|
|
void loadLanguage();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
QMap<FullMsgId, PeerId> photoUpdates;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
QMap<int32, TimeMs> killDownloadSessionTimes;
|
2014-11-12 20:30:26 +00:00
|
|
|
SingleTimer killDownloadSessionsTimer;
|
2014-10-30 16:23:44 +00:00
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
TimeMs _lastActionTime = 0;
|
2015-01-26 13:04:41 +00:00
|
|
|
|
2016-10-28 12:44:28 +00:00
|
|
|
MainWindow *_window = nullptr;
|
|
|
|
FileUploader *_uploader = nullptr;
|
|
|
|
Translator *_translator = nullptr;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
};
|