2017-02-23 10:59: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.
|
2017-02-23 10:59: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
|
2017-02-23 10:59:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-08-23 13:52:59 +00:00
|
|
|
#include "core/core_settings.h"
|
2017-06-26 17:38:16 +00:00
|
|
|
#include "mtproto/auth_key.h"
|
2019-08-23 13:52:59 +00:00
|
|
|
#include "base/observer.h"
|
2017-08-03 13:06:29 +00:00
|
|
|
#include "base/timer.h"
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2019-06-06 11:20:21 +00:00
|
|
|
class MainWindow;
|
2017-12-11 14:45:29 +00:00
|
|
|
class MainWidget;
|
|
|
|
class FileUploader;
|
|
|
|
class Translator;
|
2018-05-24 13:40:19 +00:00
|
|
|
class BoxContent;
|
2017-12-11 14:45:29 +00:00
|
|
|
|
2018-08-29 13:23:16 +00:00
|
|
|
namespace Storage {
|
|
|
|
class Databases;
|
|
|
|
} // namespace Storage
|
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
namespace Window {
|
|
|
|
struct TermsLock;
|
2019-06-06 11:20:21 +00:00
|
|
|
class Controller;
|
2018-06-03 13:30:40 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2019-03-28 08:48:32 +00:00
|
|
|
namespace ChatHelpers {
|
|
|
|
class EmojiKeywords;
|
|
|
|
} // namespace ChatHelpers
|
|
|
|
|
2017-04-29 20:06:32 +00:00
|
|
|
namespace App {
|
|
|
|
void quit();
|
|
|
|
} // namespace App
|
|
|
|
|
2019-04-30 11:12:30 +00:00
|
|
|
namespace Main {
|
|
|
|
class Account;
|
|
|
|
} // namespace Main
|
|
|
|
|
2019-02-04 13:34:50 +00:00
|
|
|
namespace Ui {
|
|
|
|
namespace Animations {
|
|
|
|
class Manager;
|
|
|
|
} // namespace Animations
|
|
|
|
} // namespace Ui
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
namespace MTP {
|
|
|
|
class DcOptions;
|
2017-02-24 17:15:41 +00:00
|
|
|
class Instance;
|
2017-06-26 17:38:16 +00:00
|
|
|
class AuthKey;
|
|
|
|
using AuthKeyPtr = std::shared_ptr<AuthKey>;
|
|
|
|
using AuthKeysList = std::vector<AuthKeyPtr>;
|
2017-02-23 10:59:19 +00:00
|
|
|
} // namespace MTP
|
|
|
|
|
2017-05-03 11:36:39 +00:00
|
|
|
namespace Media {
|
|
|
|
namespace Audio {
|
|
|
|
class Instance;
|
|
|
|
} // namespace Audio
|
2019-02-12 11:00:47 +00:00
|
|
|
namespace View {
|
|
|
|
class OverlayWidget;
|
|
|
|
} // namespace View
|
2017-05-03 11:36:39 +00:00
|
|
|
} // namespace Media
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
namespace Lang {
|
2017-04-13 17:59:05 +00:00
|
|
|
class Instance;
|
2017-04-13 08:45:58 +00:00
|
|
|
class Translator;
|
2017-04-18 15:21:03 +00:00
|
|
|
class CloudManager;
|
2017-04-13 08:45:58 +00:00
|
|
|
} // namespace Lang
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
class Launcher;
|
|
|
|
struct LocalUrlHandler;
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2019-03-27 08:37:25 +00:00
|
|
|
class Application final : public QObject, private base::Subscriber {
|
2017-02-23 10:59:19 +00:00
|
|
|
public:
|
2019-01-21 13:42:21 +00:00
|
|
|
Application(not_null<Launcher*> launcher);
|
|
|
|
Application(const Application &other) = delete;
|
|
|
|
Application &operator=(const Application &other) = delete;
|
2019-03-28 08:48:32 +00:00
|
|
|
~Application();
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
not_null<Launcher*> launcher() const {
|
2017-12-11 14:45:29 +00:00
|
|
|
return _launcher;
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void run();
|
|
|
|
|
2019-02-04 13:34:50 +00:00
|
|
|
Ui::Animations::Manager &animationManager() const {
|
|
|
|
return *_animationsManager;
|
|
|
|
}
|
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
// Windows interface.
|
2019-06-06 11:20:21 +00:00
|
|
|
Window::Controller *activeWindow() const;
|
2017-08-08 09:56:10 +00:00
|
|
|
bool closeActiveWindow();
|
|
|
|
bool minimizeActiveWindow();
|
2017-08-08 09:31:48 +00:00
|
|
|
QWidget *getFileDialogParent();
|
|
|
|
|
2019-02-12 11:00:47 +00:00
|
|
|
// Media view interface.
|
2017-08-08 09:31:48 +00:00
|
|
|
void checkMediaViewActivation();
|
|
|
|
bool hideMediaView();
|
2017-12-15 16:25:47 +00:00
|
|
|
void showPhoto(not_null<const PhotoOpenClickHandler*> link);
|
2017-08-17 08:31:24 +00:00
|
|
|
void showPhoto(not_null<PhotoData*> photo, HistoryItem *item);
|
2017-12-15 16:25:47 +00:00
|
|
|
void showPhoto(not_null<PhotoData*> photo, not_null<PeerData*> item);
|
2017-08-17 08:31:24 +00:00
|
|
|
void showDocument(not_null<DocumentData*> document, HistoryItem *item);
|
2017-08-08 09:31:48 +00:00
|
|
|
PeerData *ui_getPeerForMouseAction();
|
|
|
|
|
2017-04-19 20:25:48 +00:00
|
|
|
QPoint getPointForCallPanelCenter() const;
|
2017-05-12 15:27:19 +00:00
|
|
|
QImage logo() const {
|
|
|
|
return _logo;
|
|
|
|
}
|
|
|
|
QImage logoNoMargin() const {
|
|
|
|
return _logoNoMargin;
|
|
|
|
}
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2019-08-23 13:52:59 +00:00
|
|
|
[[nodiscard]] Settings &settings() {
|
|
|
|
return _settings;
|
|
|
|
}
|
|
|
|
void moveSettingsFrom(Settings &&other);
|
|
|
|
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
|
|
|
|
|
|
|
|
// Dc options and proxy.
|
2017-02-23 10:59:19 +00:00
|
|
|
MTP::DcOptions *dcOptions() {
|
|
|
|
return _dcOptions.get();
|
|
|
|
}
|
2019-07-24 08:46:23 +00:00
|
|
|
struct ProxyChange {
|
|
|
|
ProxyData was;
|
|
|
|
ProxyData now;
|
|
|
|
};
|
2018-11-05 13:58:24 +00:00
|
|
|
void setCurrentProxy(
|
|
|
|
const ProxyData &proxy,
|
|
|
|
ProxyData::Settings settings);
|
2019-07-24 08:46:23 +00:00
|
|
|
[[nodiscard]] rpl::producer<ProxyChange> proxyChanges() const;
|
2018-05-24 13:40:19 +00:00
|
|
|
void badMtprotoConfigurationError();
|
2017-02-24 17:15:41 +00:00
|
|
|
|
2019-04-30 11:12:30 +00:00
|
|
|
// Databases.
|
2019-07-24 14:00:30 +00:00
|
|
|
[[nodiscard]] Storage::Databases &databases() {
|
2018-08-29 13:23:16 +00:00
|
|
|
return *_databases;
|
|
|
|
}
|
|
|
|
|
2019-04-30 11:12:30 +00:00
|
|
|
// Account component.
|
2019-07-24 14:00:30 +00:00
|
|
|
[[nodiscard]] Main::Account &activeAccount() const {
|
2019-04-30 11:12:30 +00:00
|
|
|
return *_account;
|
|
|
|
}
|
2019-07-24 14:00:30 +00:00
|
|
|
[[nodiscard]] bool exportPreventsQuit();
|
2019-04-30 11:12:30 +00:00
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
// Main::Session component.
|
2019-07-24 14:00:30 +00:00
|
|
|
[[nodiscard]] int unreadBadge() const;
|
2018-12-04 10:32:06 +00:00
|
|
|
bool unreadBadgeMuted() const;
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2017-05-03 11:36:39 +00:00
|
|
|
// Media component.
|
|
|
|
Media::Audio::Instance &audio() {
|
|
|
|
return *_audio;
|
|
|
|
}
|
|
|
|
|
2019-03-28 08:48:32 +00:00
|
|
|
// Langpack and emoji keywords.
|
|
|
|
Lang::Instance &langpack() {
|
|
|
|
return *_langpack;
|
|
|
|
}
|
|
|
|
Lang::CloudManager *langCloudManager() {
|
|
|
|
return _langCloudManager.get();
|
|
|
|
}
|
|
|
|
ChatHelpers::EmojiKeywords &emojiKeywords() {
|
|
|
|
return *_emojiKeywords;
|
|
|
|
}
|
|
|
|
|
2017-06-27 20:11:38 +00:00
|
|
|
// Internal links.
|
2017-03-10 17:25:43 +00:00
|
|
|
void setInternalLinkDomain(const QString &domain) const;
|
|
|
|
QString createInternalLink(const QString &query) const;
|
|
|
|
QString createInternalLinkFull(const QString &query) const;
|
2017-06-27 20:11:38 +00:00
|
|
|
void checkStartUrl();
|
2018-07-09 18:13:48 +00:00
|
|
|
bool openLocalUrl(const QString &url, QVariant context);
|
2017-03-10 17:25:43 +00:00
|
|
|
|
2018-06-04 18:18:52 +00:00
|
|
|
void forceLogOut(const TextWithEntities &explanation);
|
2017-02-23 10:59:19 +00:00
|
|
|
void checkLocalTime();
|
2018-06-03 13:30:40 +00:00
|
|
|
void lockByPasscode();
|
|
|
|
void unlockPasscode();
|
|
|
|
[[nodiscard]] bool passcodeLocked() const;
|
|
|
|
rpl::producer<bool> passcodeLockChanges() const;
|
|
|
|
rpl::producer<bool> passcodeLockValue() const;
|
|
|
|
|
|
|
|
void lockByTerms(const Window::TermsLock &data);
|
|
|
|
void unlockTerms();
|
2018-09-21 16:28:46 +00:00
|
|
|
[[nodiscard]] std::optional<Window::TermsLock> termsLocked() const;
|
2018-06-03 13:30:40 +00:00
|
|
|
rpl::producer<bool> termsLockChanges() const;
|
|
|
|
rpl::producer<bool> termsLockValue() const;
|
|
|
|
|
|
|
|
[[nodiscard]] bool locked() const;
|
|
|
|
rpl::producer<bool> lockChanges() const;
|
|
|
|
rpl::producer<bool> lockValue() const;
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2019-03-09 17:10:51 +00:00
|
|
|
[[nodiscard]] crl::time lastNonIdleTime() const;
|
|
|
|
void updateNonIdle();
|
|
|
|
|
2017-11-21 10:27:37 +00:00
|
|
|
void registerLeaveSubscription(QWidget *widget);
|
|
|
|
void unregisterLeaveSubscription(QWidget *widget);
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
// Sandbox interface.
|
|
|
|
void postponeCall(FnMut<void()> &&callable);
|
|
|
|
void refreshGlobalProxy();
|
|
|
|
void activateWindowDelayed(not_null<QWidget*> widget);
|
|
|
|
void pauseDelayedWindowActivations();
|
|
|
|
void resumeDelayedWindowActivations();
|
|
|
|
void preventWindowActivation();
|
|
|
|
|
2017-04-29 20:06:32 +00:00
|
|
|
void quitPreventFinished();
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void handleAppActivated();
|
|
|
|
void handleAppDeactivated();
|
|
|
|
|
2019-01-18 11:26:43 +00:00
|
|
|
void switchDebugMode();
|
|
|
|
void switchWorkMode();
|
|
|
|
void switchTestMode();
|
2019-01-21 13:42:21 +00:00
|
|
|
void writeInstallBetaVersionsSetting();
|
2019-01-18 11:26:43 +00:00
|
|
|
|
2017-04-06 16:49:42 +00:00
|
|
|
void call_handleUnreadCounterUpdate();
|
|
|
|
void call_handleDelayedPeerUpdates();
|
|
|
|
void call_handleObservables();
|
2017-02-25 16:44:02 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void callDelayed(int duration, FnMut<void()> &&lambda) {
|
2017-08-03 13:06:29 +00:00
|
|
|
_callDelayedTimer.call(duration, std::move(lambda));
|
|
|
|
}
|
|
|
|
|
2017-08-08 09:31:48 +00:00
|
|
|
protected:
|
|
|
|
bool eventFilter(QObject *object, QEvent *event) override;
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
private:
|
2019-08-23 13:52:59 +00:00
|
|
|
static constexpr auto kDefaultSaveDelay = crl::time(1000);
|
|
|
|
|
2019-02-04 13:34:50 +00:00
|
|
|
friend bool IsAppLaunched();
|
|
|
|
friend Application &App();
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
void startLocalStorage();
|
2018-11-16 12:15:14 +00:00
|
|
|
void startShortcuts();
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
void stateChanged(Qt::ApplicationState state);
|
|
|
|
|
2017-04-29 20:06:32 +00:00
|
|
|
friend void App::quit();
|
|
|
|
static void QuitAttempt();
|
|
|
|
void quitDelayed();
|
|
|
|
|
2018-06-07 07:44:38 +00:00
|
|
|
void clearPasscodeLock();
|
2017-08-08 09:31:48 +00:00
|
|
|
|
2019-02-04 13:34:50 +00:00
|
|
|
static Application *Instance;
|
2019-07-24 08:46:23 +00:00
|
|
|
struct InstanceSetter {
|
|
|
|
InstanceSetter(not_null<Application*> instance) {
|
|
|
|
Expects(Instance == nullptr);
|
|
|
|
|
|
|
|
Instance = instance;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
InstanceSetter _setter = { this };
|
2019-02-04 13:34:50 +00:00
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
not_null<Launcher*> _launcher;
|
2019-07-24 08:46:23 +00:00
|
|
|
rpl::event_stream<ProxyChange> _proxyChanges;
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2017-02-24 17:15:41 +00:00
|
|
|
// Some fields are just moved from the declaration.
|
|
|
|
struct Private;
|
|
|
|
const std::unique_ptr<Private> _private;
|
2019-08-23 13:52:59 +00:00
|
|
|
Settings _settings;
|
2017-08-08 09:31:48 +00:00
|
|
|
|
2019-02-04 13:34:50 +00:00
|
|
|
const std::unique_ptr<Storage::Databases> _databases;
|
|
|
|
const std::unique_ptr<Ui::Animations::Manager> _animationsManager;
|
2019-07-24 08:46:23 +00:00
|
|
|
const std::unique_ptr<MTP::DcOptions> _dcOptions;
|
2019-04-30 11:12:30 +00:00
|
|
|
const std::unique_ptr<Main::Account> _account;
|
2019-06-06 11:20:21 +00:00
|
|
|
std::unique_ptr<Window::Controller> _window;
|
2019-02-12 11:00:47 +00:00
|
|
|
std::unique_ptr<Media::View::OverlayWidget> _mediaView;
|
2019-02-04 13:34:50 +00:00
|
|
|
const std::unique_ptr<Lang::Instance> _langpack;
|
2017-04-18 15:21:03 +00:00
|
|
|
std::unique_ptr<Lang::CloudManager> _langCloudManager;
|
2019-03-28 08:48:32 +00:00
|
|
|
const std::unique_ptr<ChatHelpers::EmojiKeywords> _emojiKeywords;
|
2017-04-13 08:45:58 +00:00
|
|
|
std::unique_ptr<Lang::Translator> _translator;
|
2017-04-15 18:48:54 +00:00
|
|
|
base::Observable<void> _passcodedChanged;
|
2018-05-24 13:40:19 +00:00
|
|
|
QPointer<BoxContent> _badProxyDisableBox;
|
2017-02-23 10:59:19 +00:00
|
|
|
|
2019-02-04 13:34:50 +00:00
|
|
|
const std::unique_ptr<Media::Audio::Instance> _audio;
|
|
|
|
const QImage _logo;
|
|
|
|
const QImage _logoNoMargin;
|
2017-05-03 11:36:39 +00:00
|
|
|
|
2018-06-03 13:30:40 +00:00
|
|
|
rpl::variable<bool> _passcodeLock;
|
|
|
|
rpl::event_stream<bool> _termsLockChanges;
|
|
|
|
std::unique_ptr<Window::TermsLock> _termsLock;
|
|
|
|
|
2017-08-03 13:06:29 +00:00
|
|
|
base::DelayedCallTimer _callDelayedTimer;
|
2019-08-23 13:52:59 +00:00
|
|
|
base::Timer _saveSettingsTimer;
|
2017-08-03 13:06:29 +00:00
|
|
|
|
2017-11-21 10:27:37 +00:00
|
|
|
struct LeaveSubscription {
|
2017-12-22 07:05:20 +00:00
|
|
|
LeaveSubscription(
|
|
|
|
QPointer<QWidget> pointer,
|
|
|
|
rpl::lifetime &&subscription)
|
2017-11-21 10:27:37 +00:00
|
|
|
: pointer(pointer), subscription(std::move(subscription)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointer<QWidget> pointer;
|
|
|
|
rpl::lifetime subscription;
|
|
|
|
};
|
|
|
|
std::vector<LeaveSubscription> _leaveSubscriptions;
|
|
|
|
|
2018-11-16 12:15:14 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2019-03-09 17:10:51 +00:00
|
|
|
crl::time _lastNonIdleTime = 0;
|
|
|
|
|
2017-02-23 10:59:19 +00:00
|
|
|
};
|
2019-01-21 13:42:21 +00:00
|
|
|
|
2019-02-04 13:34:50 +00:00
|
|
|
[[nodiscard]] bool IsAppLaunched();
|
|
|
|
[[nodiscard]] Application &App();
|
2019-01-21 13:42:21 +00:00
|
|
|
|
|
|
|
} // namespace Core
|