mirror of https://github.com/procxx/kepka.git
Moved AppClass to messenger.cpp:Messenger.
This commit is contained in:
parent
63c61637f8
commit
c3b3819d9f
|
@ -37,8 +37,10 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "history/history_media_types.h"
|
||||
#include "media/media_audio.h"
|
||||
#include "inline_bots/inline_bot_layout_item.h"
|
||||
#include "messenger.h"
|
||||
#include "application.h"
|
||||
#include "fileuploader.h"
|
||||
#include "mainwindow.h"
|
||||
#include "mainwidget.h"
|
||||
#include "localstorage.h"
|
||||
#include "apiwrap.h"
|
||||
|
@ -160,24 +162,27 @@ namespace App {
|
|||
return result;
|
||||
}
|
||||
|
||||
AppClass *app() {
|
||||
return AppClass::app();
|
||||
Messenger *app() {
|
||||
return Messenger::InstancePointer();
|
||||
}
|
||||
|
||||
MainWindow *wnd() {
|
||||
return AppClass::wnd();
|
||||
if (auto instance = app()) {
|
||||
return instance->mainWindow();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MainWidget *main() {
|
||||
if (auto w = wnd()) {
|
||||
return w->mainWidget();
|
||||
if (auto window = wnd()) {
|
||||
return window->mainWidget();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool passcoded() {
|
||||
if (auto w = wnd()) {
|
||||
return w->passcodeWidget();
|
||||
if (auto window = wnd()) {
|
||||
return window->passcodeWidget();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -202,7 +207,7 @@ namespace {
|
|||
w->notifyClearFast();
|
||||
w->setupIntro();
|
||||
}
|
||||
AppClass::Instance().authSessionDestroy();
|
||||
Messenger::Instance().authSessionDestroy();
|
||||
Local::reset();
|
||||
Window::Theme::Background()->reset();
|
||||
|
||||
|
@ -2460,11 +2465,11 @@ namespace {
|
|||
if (auto apiwrap = api()) {
|
||||
if (apiwrap->hasUnsavedDrafts()) {
|
||||
apiwrap->saveDraftsToCloud();
|
||||
QTimer::singleShot(SaveDraftBeforeQuitTimeout, Application::instance(), SLOT(quit()));
|
||||
QTimer::singleShot(SaveDraftBeforeQuitTimeout, QCoreApplication::instance(), SLOT(quit()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
Application::quit();
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
|
||||
bool quitting() {
|
||||
|
@ -2473,7 +2478,7 @@ namespace {
|
|||
|
||||
void allDraftsSaved() {
|
||||
if (quitting()) {
|
||||
Application::quit();
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "history/history_message.h"
|
||||
#include "layout.h"
|
||||
|
||||
class AppClass;
|
||||
class Messenger;
|
||||
class MainWindow;
|
||||
class MainWidget;
|
||||
class ApiWrap;
|
||||
|
@ -48,7 +48,7 @@ class LocationCoords;
|
|||
struct LocationData;
|
||||
|
||||
namespace App {
|
||||
AppClass *app();
|
||||
Messenger *app();
|
||||
MainWindow *wnd();
|
||||
MainWidget *main();
|
||||
bool passcoded();
|
||||
|
|
|
@ -25,6 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "pspecific.h"
|
||||
#include "fileuploader.h"
|
||||
#include "mainwidget.h"
|
||||
#include "mainwindow.h"
|
||||
#include "lang.h"
|
||||
#include "boxes/confirmbox.h"
|
||||
#include "ui/filedialog.h"
|
||||
|
@ -40,22 +41,12 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "history/history_location_manager.h"
|
||||
#include "core/task_queue.h"
|
||||
#include "mtproto/dc_options.h"
|
||||
#include "core/single_timer.h"
|
||||
#include "auth_session.h"
|
||||
#include "messenger.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void mtpStateChanged(int32 dc, int32 state) {
|
||||
if (App::wnd()) {
|
||||
App::wnd()->mtpStateChanged(dc, state);
|
||||
}
|
||||
}
|
||||
|
||||
void mtpSessionReset(int32 dc) {
|
||||
if (App::main() && dc == MTP::maindc()) {
|
||||
App::main()->getDifference();
|
||||
}
|
||||
}
|
||||
|
||||
QChar _toHex(ushort v) {
|
||||
v = v & 0x000F;
|
||||
return QChar::fromLatin1((v >= 10) ? ('a' + (v - 10)) : ('0' + v));
|
||||
|
@ -96,8 +87,6 @@ QString _escapeFrom7bit(const QString &str) {
|
|||
|
||||
} // namespace
|
||||
|
||||
AppClass *AppObject = nullptr;
|
||||
|
||||
Application::Application(int &argc, char **argv) : QApplication(argc, argv) {
|
||||
QByteArray d(QFile::encodeName(QDir(cWorkingDir()).absolutePath()));
|
||||
char h[33] = { 0 };
|
||||
|
@ -120,7 +109,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) {
|
|||
connect(this, SIGNAL(aboutToQuit()), this, SLOT(closeApplication()));
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
||||
connect(&_updateCheckTimer, SIGNAL(timeout()), this, SLOT(updateCheck()));
|
||||
_updateCheckTimer.create(this);
|
||||
connect(_updateCheckTimer, SIGNAL(timeout()), this, SLOT(updateCheck()));
|
||||
connect(this, SIGNAL(updateFailed()), this, SLOT(onUpdateFailed()));
|
||||
connect(this, SIGNAL(updateReady()), this, SLOT(onUpdateReady()));
|
||||
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
|
||||
|
@ -134,6 +124,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) {
|
|||
}
|
||||
}
|
||||
|
||||
Application::~Application() = default;
|
||||
|
||||
bool Application::event(QEvent *e) {
|
||||
if (e->type() == QEvent::Close) {
|
||||
App::quit();
|
||||
|
@ -334,6 +326,11 @@ void Application::startApplication() {
|
|||
}
|
||||
}
|
||||
|
||||
void Application::createMessenger() {
|
||||
t_assert(!App::quitting());
|
||||
_messengerInstance = std::make_unique<Messenger>();
|
||||
}
|
||||
|
||||
void Application::closeApplication() {
|
||||
if (App::launchState() == App::QuitProcessed) return;
|
||||
App::setLaunchState(App::QuitProcessed);
|
||||
|
@ -342,9 +339,9 @@ void Application::closeApplication() {
|
|||
manager->clearAllFast();
|
||||
}
|
||||
|
||||
if (AppObject) {
|
||||
AppClass::Instance().joinThreads();
|
||||
delete base::take(AppObject);
|
||||
if (_messengerInstance) {
|
||||
Messenger::Instance().prepareToDestroy();
|
||||
_messengerInstance.reset();
|
||||
}
|
||||
|
||||
Sandbox::finish();
|
||||
|
@ -429,9 +426,9 @@ void Application::updateFailedCurrent(QNetworkReply::NetworkError e) {
|
|||
void Application::onUpdateReady() {
|
||||
if (_updateChecker) {
|
||||
_updateChecker->deleteLater();
|
||||
_updateChecker = 0;
|
||||
_updateChecker = nullptr;
|
||||
}
|
||||
_updateCheckTimer.stop();
|
||||
_updateCheckTimer->stop();
|
||||
|
||||
cSetLastUpdateCheck(unixtime());
|
||||
Local::writeSettings();
|
||||
|
@ -482,7 +479,7 @@ void Application::stopUpdate() {
|
|||
void Application::startUpdateCheck(bool forceWait) {
|
||||
if (!Sandbox::started()) return;
|
||||
|
||||
_updateCheckTimer.stop();
|
||||
_updateCheckTimer->stop();
|
||||
if (_updateThread || _updateReply || !cAutoUpdate()) return;
|
||||
|
||||
int32 constDelay = cBetaVersion() ? 600 : UpdateDelayConstPart, randDelay = cBetaVersion() ? 300 : UpdateDelayRandPart;
|
||||
|
@ -520,7 +517,7 @@ void Application::startUpdateCheck(bool forceWait) {
|
|||
connect(_updateReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(updateFailedCurrent(QNetworkReply::NetworkError)));
|
||||
emit updateChecking();
|
||||
} else {
|
||||
_updateCheckTimer.start((updateInSecs + 5) * 1000);
|
||||
_updateCheckTimer->start((updateInSecs + 5) * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -532,638 +529,154 @@ inline Application *application() {
|
|||
|
||||
namespace Sandbox {
|
||||
|
||||
QRect availableGeometry() {
|
||||
if (Application *a = application()) {
|
||||
return a->desktop()->availableGeometry();
|
||||
}
|
||||
return QDesktopWidget().availableGeometry();
|
||||
QRect availableGeometry() {
|
||||
if (auto a = application()) {
|
||||
return a->desktop()->availableGeometry();
|
||||
}
|
||||
return QDesktopWidget().availableGeometry();
|
||||
}
|
||||
|
||||
QRect screenGeometry(const QPoint &p) {
|
||||
if (Application *a = application()) {
|
||||
return a->desktop()->screenGeometry(p);
|
||||
}
|
||||
return QDesktopWidget().screenGeometry(p);
|
||||
QRect screenGeometry(const QPoint &p) {
|
||||
if (auto a = application()) {
|
||||
return a->desktop()->screenGeometry(p);
|
||||
}
|
||||
return QDesktopWidget().screenGeometry(p);
|
||||
}
|
||||
|
||||
void setActiveWindow(QWidget *window) {
|
||||
if (Application *a = application()) {
|
||||
a->setActiveWindow(window);
|
||||
}
|
||||
}
|
||||
|
||||
bool isSavingSession() {
|
||||
if (Application *a = application()) {
|
||||
return a->isSavingSession();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void installEventFilter(QObject *filter) {
|
||||
if (Application *a = application()) {
|
||||
a->installEventFilter(filter);
|
||||
}
|
||||
}
|
||||
|
||||
void removeEventFilter(QObject *filter) {
|
||||
if (Application *a = application()) {
|
||||
a->removeEventFilter(filter);
|
||||
}
|
||||
}
|
||||
|
||||
void execExternal(const QString &cmd) {
|
||||
DEBUG_LOG(("Application Info: executing external command '%1'").arg(cmd));
|
||||
if (cmd == "show") {
|
||||
if (App::wnd()) {
|
||||
App::wnd()->activate();
|
||||
} else if (PreLaunchWindow::instance()) {
|
||||
PreLaunchWindow::instance()->activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
||||
|
||||
void startUpdateCheck() {
|
||||
if (Application *a = application()) {
|
||||
return a->startUpdateCheck(false);
|
||||
}
|
||||
}
|
||||
|
||||
void stopUpdate() {
|
||||
if (Application *a = application()) {
|
||||
return a->stopUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
Application::UpdatingState updatingState() {
|
||||
if (Application *a = application()) {
|
||||
return a->updatingState();
|
||||
}
|
||||
return Application::UpdatingNone;
|
||||
}
|
||||
|
||||
int32 updatingSize() {
|
||||
if (Application *a = application()) {
|
||||
return a->updatingSize();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 updatingReady() {
|
||||
if (Application *a = application()) {
|
||||
return a->updatingReady();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void updateChecking() {
|
||||
if (Application *a = application()) {
|
||||
emit a->updateChecking();
|
||||
}
|
||||
}
|
||||
|
||||
void updateLatest() {
|
||||
if (Application *a = application()) {
|
||||
emit a->updateLatest();
|
||||
}
|
||||
}
|
||||
|
||||
void updateProgress(qint64 ready, qint64 total) {
|
||||
if (Application *a = application()) {
|
||||
emit a->updateProgress(ready, total);
|
||||
}
|
||||
}
|
||||
|
||||
void updateFailed() {
|
||||
if (Application *a = application()) {
|
||||
emit a->updateFailed();
|
||||
}
|
||||
}
|
||||
|
||||
void updateReady() {
|
||||
if (Application *a = application()) {
|
||||
emit a->updateReady();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
|
||||
|
||||
void connect(const char *signal, QObject *object, const char *method) {
|
||||
if (Application *a = application()) {
|
||||
a->connect(a, signal, object, method);
|
||||
}
|
||||
}
|
||||
|
||||
void launch() {
|
||||
t_assert(application() != 0);
|
||||
|
||||
float64 dpi = Application::primaryScreen()->logicalDotsPerInch();
|
||||
if (dpi <= 108) { // 0-96-108
|
||||
cSetScreenScale(dbisOne);
|
||||
} else if (dpi <= 132) { // 108-120-132
|
||||
cSetScreenScale(dbisOneAndQuarter);
|
||||
} else if (dpi <= 168) { // 132-144-168
|
||||
cSetScreenScale(dbisOneAndHalf);
|
||||
} else { // 168-192-inf
|
||||
cSetScreenScale(dbisTwo);
|
||||
}
|
||||
|
||||
auto devicePixelRatio = application()->devicePixelRatio();
|
||||
if (devicePixelRatio > 1.) {
|
||||
if ((cPlatform() != dbipMac && cPlatform() != dbipMacOld) || (devicePixelRatio != 2.)) {
|
||||
LOG(("Found non-trivial Device Pixel Ratio: %1").arg(devicePixelRatio));
|
||||
LOG(("Environmental variables: QT_DEVICE_PIXEL_RATIO='%1'").arg(QString::fromLatin1(qgetenv("QT_DEVICE_PIXEL_RATIO"))));
|
||||
LOG(("Environmental variables: QT_SCALE_FACTOR='%1'").arg(QString::fromLatin1(qgetenv("QT_SCALE_FACTOR"))));
|
||||
LOG(("Environmental variables: QT_AUTO_SCREEN_SCALE_FACTOR='%1'").arg(QString::fromLatin1(qgetenv("QT_AUTO_SCREEN_SCALE_FACTOR"))));
|
||||
LOG(("Environmental variables: QT_SCREEN_SCALE_FACTORS='%1'").arg(QString::fromLatin1(qgetenv("QT_SCREEN_SCALE_FACTORS"))));
|
||||
}
|
||||
cSetRetina(true);
|
||||
cSetRetinaFactor(devicePixelRatio);
|
||||
cSetIntRetinaFactor(int32(cRetinaFactor()));
|
||||
cSetConfigScale(dbisOne);
|
||||
cSetRealScale(dbisOne);
|
||||
}
|
||||
|
||||
new AppClass();
|
||||
void setActiveWindow(QWidget *window) {
|
||||
if (auto a = application()) {
|
||||
a->setActiveWindow(window);
|
||||
}
|
||||
}
|
||||
|
||||
AppClass::AppClass() : QObject() {
|
||||
AppObject = this;
|
||||
|
||||
Fonts::start();
|
||||
|
||||
ThirdParty::start();
|
||||
Global::start();
|
||||
|
||||
startLocalStorage();
|
||||
|
||||
if (Local::oldSettingsVersion() < AppVersion) {
|
||||
psNewVersion();
|
||||
}
|
||||
|
||||
if (cLaunchMode() == LaunchModeAutoStart && !cAutoStart()) {
|
||||
psAutoStart(false, true);
|
||||
App::quit();
|
||||
return;
|
||||
}
|
||||
|
||||
if (cRetina()) {
|
||||
cSetConfigScale(dbisOne);
|
||||
cSetRealScale(dbisOne);
|
||||
}
|
||||
loadLanguage();
|
||||
style::startManager();
|
||||
anim::startManager();
|
||||
historyInit();
|
||||
Media::Player::start();
|
||||
Window::Notifications::start();
|
||||
|
||||
DEBUG_LOG(("Application Info: inited..."));
|
||||
|
||||
application()->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.
|
||||
QMimeDatabase().mimeTypeForName(qsl("text/plain"));
|
||||
|
||||
_window = new MainWindow();
|
||||
_window->createWinId();
|
||||
_window->init();
|
||||
|
||||
Sandbox::connect(SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onAppStateChanged(Qt::ApplicationState)));
|
||||
|
||||
DEBUG_LOG(("Application Info: window created..."));
|
||||
|
||||
Shortcuts::start();
|
||||
|
||||
initLocationManager();
|
||||
App::initMedia();
|
||||
|
||||
Local::ReadMapState state = Local::readMap(QByteArray());
|
||||
if (state == Local::ReadMapPassNeeded) {
|
||||
Global::SetLocalPasscode(true);
|
||||
Global::RefLocalPasscodeChanged().notify();
|
||||
DEBUG_LOG(("Application Info: passcode needed..."));
|
||||
} else {
|
||||
DEBUG_LOG(("Application Info: local map read..."));
|
||||
MTP::start();
|
||||
}
|
||||
|
||||
MTP::setStateChangedHandler(mtpStateChanged);
|
||||
MTP::setSessionResetHandler(mtpSessionReset);
|
||||
|
||||
DEBUG_LOG(("Application Info: MTP started..."));
|
||||
|
||||
DEBUG_LOG(("Application Info: showing."));
|
||||
if (state == Local::ReadMapPassNeeded) {
|
||||
_window->setupPasscode();
|
||||
} else {
|
||||
if (AuthSession::Current()) {
|
||||
_window->setupMain();
|
||||
} else {
|
||||
_window->setupIntro();
|
||||
}
|
||||
}
|
||||
_window->firstShow();
|
||||
|
||||
if (cStartToSettings()) {
|
||||
_window->showSettings();
|
||||
}
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
||||
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
||||
#endif // !TDESKTOP_DISABLE_NETWORK_PROXY
|
||||
|
||||
if (state != Local::ReadMapPassNeeded) {
|
||||
checkMapVersion();
|
||||
}
|
||||
|
||||
_window->updateIsActive(Global::OnlineFocusTimeout());
|
||||
|
||||
if (!Shortcuts::errors().isEmpty()) {
|
||||
const QStringList &errors(Shortcuts::errors());
|
||||
for (QStringList::const_iterator i = errors.cbegin(), e = errors.cend(); i != e; ++i) {
|
||||
LOG(("Shortcuts Error: %1").arg(*i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppClass::loadLanguage() {
|
||||
if (cLang() < languageTest) {
|
||||
cSetLang(Sandbox::LangSystem());
|
||||
}
|
||||
if (cLang() == languageTest) {
|
||||
if (QFileInfo(cLangFile()).exists()) {
|
||||
LangLoaderPlain loader(cLangFile());
|
||||
cSetLangErrors(loader.errors());
|
||||
if (!cLangErrors().isEmpty()) {
|
||||
LOG(("Lang load errors: %1").arg(cLangErrors()));
|
||||
} else if (!loader.warnings().isEmpty()) {
|
||||
LOG(("Lang load warnings: %1").arg(loader.warnings()));
|
||||
}
|
||||
} else {
|
||||
cSetLang(languageDefault);
|
||||
}
|
||||
} else if (cLang() > languageDefault && cLang() < languageCount) {
|
||||
LangLoaderPlain loader(qsl(":/langs/lang_") + LanguageCodes[cLang()].c_str() + qsl(".strings"));
|
||||
if (!loader.errors().isEmpty()) {
|
||||
LOG(("Lang load errors: %1").arg(loader.errors()));
|
||||
} else if (!loader.warnings().isEmpty()) {
|
||||
LOG(("Lang load warnings: %1").arg(loader.warnings()));
|
||||
}
|
||||
}
|
||||
application()->installTranslator(_translator = new Translator());
|
||||
}
|
||||
|
||||
void AppClass::startLocalStorage() {
|
||||
_dcOptions = std::make_unique<MTP::DcOptions>();
|
||||
_dcOptions->constructFromBuiltIn();
|
||||
Local::start();
|
||||
subscribe(_dcOptions->changed(), [](const MTP::DcOptions::Ids &ids) {
|
||||
Local::writeSettings();
|
||||
for (auto id : ids) {
|
||||
MTP::restart(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void AppClass::regPhotoUpdate(const PeerId &peer, const FullMsgId &msgId) {
|
||||
photoUpdates.insert(msgId, peer);
|
||||
}
|
||||
|
||||
bool AppClass::isPhotoUpdating(const PeerId &peer) {
|
||||
for (QMap<FullMsgId, PeerId>::iterator i = photoUpdates.begin(), e = photoUpdates.end(); i != e; ++i) {
|
||||
if (i.value() == peer) {
|
||||
return true;
|
||||
}
|
||||
bool isSavingSession() {
|
||||
if (auto a = application()) {
|
||||
return a->isSavingSession();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AppClass::cancelPhotoUpdate(const PeerId &peer) {
|
||||
for (QMap<FullMsgId, PeerId>::iterator i = photoUpdates.begin(), e = photoUpdates.end(); i != e;) {
|
||||
if (i.value() == peer) {
|
||||
i = photoUpdates.erase(i);
|
||||
} else {
|
||||
++i;
|
||||
void execExternal(const QString &cmd) {
|
||||
DEBUG_LOG(("Application Info: executing external command '%1'").arg(cmd));
|
||||
if (cmd == "show") {
|
||||
if (App::wnd()) {
|
||||
App::wnd()->activate();
|
||||
} else if (PreLaunchWindow::instance()) {
|
||||
PreLaunchWindow::instance()->activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppClass::selfPhotoCleared(const MTPUserProfilePhoto &result) {
|
||||
if (!App::self()) return;
|
||||
App::self()->setPhoto(result);
|
||||
emit peerPhotoDone(App::self()->id);
|
||||
}
|
||||
|
||||
void AppClass::chatPhotoCleared(PeerId peer, const MTPUpdates &updates) {
|
||||
if (App::main()) {
|
||||
App::main()->sentUpdatesReceived(updates);
|
||||
void adjustSingleTimers() {
|
||||
if (auto a = application()) {
|
||||
a->adjustSingleTimers();
|
||||
}
|
||||
cancelPhotoUpdate(peer);
|
||||
emit peerPhotoDone(peer);
|
||||
}
|
||||
|
||||
void AppClass::selfPhotoDone(const MTPphotos_Photo &result) {
|
||||
if (!App::self()) return;
|
||||
const auto &photo(result.c_photos_photo());
|
||||
App::feedPhoto(photo.vphoto);
|
||||
App::feedUsers(photo.vusers);
|
||||
cancelPhotoUpdate(App::self()->id);
|
||||
emit peerPhotoDone(App::self()->id);
|
||||
}
|
||||
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
||||
|
||||
void AppClass::chatPhotoDone(PeerId peer, const MTPUpdates &updates) {
|
||||
if (App::main()) {
|
||||
App::main()->sentUpdatesReceived(updates);
|
||||
void startUpdateCheck() {
|
||||
if (auto a = application()) {
|
||||
return a->startUpdateCheck(false);
|
||||
}
|
||||
cancelPhotoUpdate(peer);
|
||||
emit peerPhotoDone(peer);
|
||||
}
|
||||
|
||||
bool AppClass::peerPhotoFail(PeerId peer, const RPCError &error) {
|
||||
if (MTP::isDefaultHandledError(error)) return false;
|
||||
|
||||
LOG(("Application Error: update photo failed %1: %2").arg(error.type()).arg(error.description()));
|
||||
cancelPhotoUpdate(peer);
|
||||
emit peerPhotoFail(peer);
|
||||
return true;
|
||||
void stopUpdate() {
|
||||
if (auto a = application()) {
|
||||
return a->stopUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void AppClass::peerClearPhoto(PeerId id) {
|
||||
if (!AuthSession::Current()) return;
|
||||
Application::UpdatingState updatingState() {
|
||||
if (auto a = application()) {
|
||||
return a->updatingState();
|
||||
}
|
||||
return Application::UpdatingNone;
|
||||
}
|
||||
|
||||
if (id == AuthSession::CurrentUserPeerId()) {
|
||||
MTP::send(MTPphotos_UpdateProfilePhoto(MTP_inputPhotoEmpty()), rpcDone(&AppClass::selfPhotoCleared), rpcFail(&AppClass::peerPhotoFail, id));
|
||||
} else if (peerIsChat(id)) {
|
||||
MTP::send(MTPmessages_EditChatPhoto(peerToBareMTPInt(id), MTP_inputChatPhotoEmpty()), rpcDone(&AppClass::chatPhotoCleared, id), rpcFail(&AppClass::peerPhotoFail, id));
|
||||
} else if (peerIsChannel(id)) {
|
||||
if (auto channel = App::channelLoaded(id)) {
|
||||
MTP::send(MTPchannels_EditPhoto(channel->inputChannel, MTP_inputChatPhotoEmpty()), rpcDone(&AppClass::chatPhotoCleared, id), rpcFail(&AppClass::peerPhotoFail, id));
|
||||
int32 updatingSize() {
|
||||
if (auto a = application()) {
|
||||
return a->updatingSize();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 updatingReady() {
|
||||
if (auto a = application()) {
|
||||
return a->updatingReady();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void updateChecking() {
|
||||
if (auto a = application()) {
|
||||
emit a->updateChecking();
|
||||
}
|
||||
}
|
||||
|
||||
void updateLatest() {
|
||||
if (auto a = application()) {
|
||||
emit a->updateLatest();
|
||||
}
|
||||
}
|
||||
|
||||
void updateProgress(qint64 ready, qint64 total) {
|
||||
if (auto a = application()) {
|
||||
emit a->updateProgress(ready, total);
|
||||
}
|
||||
}
|
||||
|
||||
void updateFailed() {
|
||||
if (auto a = application()) {
|
||||
emit a->updateFailed();
|
||||
}
|
||||
}
|
||||
|
||||
void updateReady() {
|
||||
if (auto a = application()) {
|
||||
emit a->updateReady();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
|
||||
|
||||
void connect(const char *signal, QObject *object, const char *method) {
|
||||
if (auto a = application()) {
|
||||
a->connect(a, signal, object, method);
|
||||
}
|
||||
}
|
||||
|
||||
void launch() {
|
||||
t_assert(application() != 0);
|
||||
|
||||
float64 dpi = Application::primaryScreen()->logicalDotsPerInch();
|
||||
if (dpi <= 108) { // 0-96-108
|
||||
cSetScreenScale(dbisOne);
|
||||
} else if (dpi <= 132) { // 108-120-132
|
||||
cSetScreenScale(dbisOneAndQuarter);
|
||||
} else if (dpi <= 168) { // 132-144-168
|
||||
cSetScreenScale(dbisOneAndHalf);
|
||||
} else { // 168-192-inf
|
||||
cSetScreenScale(dbisTwo);
|
||||
}
|
||||
|
||||
auto devicePixelRatio = application()->devicePixelRatio();
|
||||
if (devicePixelRatio > 1.) {
|
||||
if ((cPlatform() != dbipMac && cPlatform() != dbipMacOld) || (devicePixelRatio != 2.)) {
|
||||
LOG(("Found non-trivial Device Pixel Ratio: %1").arg(devicePixelRatio));
|
||||
LOG(("Environmental variables: QT_DEVICE_PIXEL_RATIO='%1'").arg(QString::fromLatin1(qgetenv("QT_DEVICE_PIXEL_RATIO"))));
|
||||
LOG(("Environmental variables: QT_SCALE_FACTOR='%1'").arg(QString::fromLatin1(qgetenv("QT_SCALE_FACTOR"))));
|
||||
LOG(("Environmental variables: QT_AUTO_SCREEN_SCALE_FACTOR='%1'").arg(QString::fromLatin1(qgetenv("QT_AUTO_SCREEN_SCALE_FACTOR"))));
|
||||
LOG(("Environmental variables: QT_SCREEN_SCALE_FACTORS='%1'").arg(QString::fromLatin1(qgetenv("QT_SCREEN_SCALE_FACTORS"))));
|
||||
}
|
||||
cSetRetina(true);
|
||||
cSetRetinaFactor(devicePixelRatio);
|
||||
cSetIntRetinaFactor(int32(cRetinaFactor()));
|
||||
cSetConfigScale(dbisOne);
|
||||
cSetRealScale(dbisOne);
|
||||
}
|
||||
|
||||
application()->createMessenger();
|
||||
}
|
||||
|
||||
void AppClass::killDownloadSessionsStart(int32 dc) {
|
||||
if (killDownloadSessionTimes.constFind(dc) == killDownloadSessionTimes.cend()) {
|
||||
killDownloadSessionTimes.insert(dc, getms() + MTPAckSendWaiting + MTPKillFileSessionTimeout);
|
||||
}
|
||||
if (!killDownloadSessionsTimer.isActive()) {
|
||||
killDownloadSessionsTimer.start(MTPAckSendWaiting + MTPKillFileSessionTimeout + 5);
|
||||
}
|
||||
}
|
||||
|
||||
void AppClass::killDownloadSessionsStop(int32 dc) {
|
||||
killDownloadSessionTimes.remove(dc);
|
||||
if (killDownloadSessionTimes.isEmpty() && killDownloadSessionsTimer.isActive()) {
|
||||
killDownloadSessionsTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
void AppClass::checkLocalTime() {
|
||||
if (App::main()) App::main()->checkLastUpdate(checkms());
|
||||
}
|
||||
|
||||
void AppClass::onAppStateChanged(Qt::ApplicationState state) {
|
||||
if (state == Qt::ApplicationActive) {
|
||||
handleAppActivated();
|
||||
} else {
|
||||
handleAppDeactivated();
|
||||
}
|
||||
}
|
||||
|
||||
void AppClass::handleAppActivated() {
|
||||
checkLocalTime();
|
||||
if (_window) {
|
||||
_window->updateIsActive(Global::OnlineFocusTimeout());
|
||||
}
|
||||
}
|
||||
|
||||
void AppClass::handleAppDeactivated() {
|
||||
if (_window) {
|
||||
_window->updateIsActive(Global::OfflineBlurTimeout());
|
||||
}
|
||||
Ui::Tooltip::Hide();
|
||||
}
|
||||
|
||||
void AppClass::call_handleHistoryUpdate() {
|
||||
Notify::handlePendingHistoryUpdate();
|
||||
}
|
||||
|
||||
void AppClass::call_handleUnreadCounterUpdate() {
|
||||
Global::RefUnreadCounterUpdate().notify(true);
|
||||
}
|
||||
|
||||
void AppClass::call_handleFileDialogQueue() {
|
||||
while (true) {
|
||||
if (!FileDialog::processQuery()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppClass::call_handleDelayedPeerUpdates() {
|
||||
Notify::peerUpdatedSendDelayed();
|
||||
}
|
||||
|
||||
void AppClass::call_handleObservables() {
|
||||
base::HandleObservables();
|
||||
}
|
||||
|
||||
void AppClass::killDownloadSessions() {
|
||||
auto ms = getms(), left = static_cast<TimeMs>(MTPAckSendWaiting) + MTPKillFileSessionTimeout;
|
||||
for (auto i = killDownloadSessionTimes.begin(); i != killDownloadSessionTimes.end(); ) {
|
||||
if (i.value() <= ms) {
|
||||
for (int j = 0; j < MTPDownloadSessionsCount; ++j) {
|
||||
MTP::stopSession(MTP::dldDcId(i.key(), j));
|
||||
}
|
||||
i = killDownloadSessionTimes.erase(i);
|
||||
} else {
|
||||
if (i.value() - ms < left) {
|
||||
left = i.value() - ms;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
if (!killDownloadSessionTimes.isEmpty()) {
|
||||
killDownloadSessionsTimer.start(left);
|
||||
}
|
||||
}
|
||||
|
||||
void AppClass::photoUpdated(const FullMsgId &msgId, bool silent, const MTPInputFile &file) {
|
||||
if (!AuthSession::Current()) return;
|
||||
|
||||
auto i = photoUpdates.find(msgId);
|
||||
if (i != photoUpdates.end()) {
|
||||
auto id = i.value();
|
||||
if (id == AuthSession::CurrentUserPeerId()) {
|
||||
MTP::send(MTPphotos_UploadProfilePhoto(file), rpcDone(&AppClass::selfPhotoDone), rpcFail(&AppClass::peerPhotoFail, id));
|
||||
} else if (peerIsChat(id)) {
|
||||
auto history = App::history(id);
|
||||
history->sendRequestId = MTP::send(MTPmessages_EditChatPhoto(history->peer->asChat()->inputChat, MTP_inputChatUploadedPhoto(file)), rpcDone(&AppClass::chatPhotoDone, id), rpcFail(&AppClass::peerPhotoFail, id), 0, 0, history->sendRequestId);
|
||||
} else if (peerIsChannel(id)) {
|
||||
auto history = App::history(id);
|
||||
history->sendRequestId = MTP::send(MTPchannels_EditPhoto(history->peer->asChannel()->inputChannel, MTP_inputChatUploadedPhoto(file)), rpcDone(&AppClass::chatPhotoDone, id), rpcFail(&AppClass::peerPhotoFail, id), 0, 0, history->sendRequestId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppClass::onSwitchDebugMode() {
|
||||
if (cDebug()) {
|
||||
QFile(cWorkingDir() + qsl("tdata/withdebug")).remove();
|
||||
cSetDebug(false);
|
||||
App::restart();
|
||||
} else {
|
||||
cSetDebug(true);
|
||||
DEBUG_LOG(("Debug logs started."));
|
||||
QFile f(cWorkingDir() + qsl("tdata/withdebug"));
|
||||
if (f.open(QIODevice::WriteOnly)) {
|
||||
f.write("1");
|
||||
f.close();
|
||||
}
|
||||
Ui::hideLayer();
|
||||
}
|
||||
}
|
||||
|
||||
void AppClass::onSwitchWorkMode() {
|
||||
Global::SetDialogsModeEnabled(!Global::DialogsModeEnabled());
|
||||
Global::SetDialogsMode(Dialogs::Mode::All);
|
||||
Local::writeUserSettings();
|
||||
App::restart();
|
||||
}
|
||||
|
||||
void AppClass::onSwitchTestMode() {
|
||||
if (cTestMode()) {
|
||||
QFile(cWorkingDir() + qsl("tdata/withtestmode")).remove();
|
||||
cSetTestMode(false);
|
||||
} else {
|
||||
QFile f(cWorkingDir() + qsl("tdata/withtestmode"));
|
||||
if (f.open(QIODevice::WriteOnly)) {
|
||||
f.write("1");
|
||||
f.close();
|
||||
}
|
||||
cSetTestMode(true);
|
||||
}
|
||||
App::restart();
|
||||
}
|
||||
|
||||
void AppClass::authSessionCreate(UserId userId) {
|
||||
_authSession = std::make_unique<AuthSession>(userId);
|
||||
}
|
||||
|
||||
void AppClass::authSessionDestroy() {
|
||||
_authSession.reset();
|
||||
}
|
||||
|
||||
FileUploader *AppClass::uploader() {
|
||||
if (!_uploader && !App::quitting()) _uploader = new FileUploader();
|
||||
return _uploader;
|
||||
}
|
||||
|
||||
void AppClass::uploadProfilePhoto(const QImage &tosend, const PeerId &peerId) {
|
||||
PreparedPhotoThumbs photoThumbs;
|
||||
QVector<MTPPhotoSize> photoSizes;
|
||||
|
||||
auto thumb = App::pixmapFromImageInPlace(tosend.scaled(160, 160, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
photoThumbs.insert('a', thumb);
|
||||
photoSizes.push_back(MTP_photoSize(MTP_string("a"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(thumb.width()), MTP_int(thumb.height()), MTP_int(0)));
|
||||
|
||||
auto medium = App::pixmapFromImageInPlace(tosend.scaled(320, 320, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
photoThumbs.insert('b', medium);
|
||||
photoSizes.push_back(MTP_photoSize(MTP_string("b"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(medium.width()), MTP_int(medium.height()), MTP_int(0)));
|
||||
|
||||
auto full = QPixmap::fromImage(tosend, Qt::ColorOnly);
|
||||
photoThumbs.insert('c', full);
|
||||
photoSizes.push_back(MTP_photoSize(MTP_string("c"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0)));
|
||||
|
||||
QByteArray jpeg;
|
||||
QBuffer jpegBuffer(&jpeg);
|
||||
full.save(&jpegBuffer, "JPG", 87);
|
||||
|
||||
PhotoId id = rand_value<PhotoId>();
|
||||
|
||||
MTPDphoto::Flags photoFlags = 0;
|
||||
auto photo = MTP_photo(MTP_flags(photoFlags), MTP_long(id), MTP_long(0), MTP_int(unixtime()), MTP_vector<MTPPhotoSize>(photoSizes));
|
||||
|
||||
QString file, filename;
|
||||
int32 filesize = 0;
|
||||
QByteArray data;
|
||||
|
||||
SendMediaReady ready(SendMediaType::Photo, file, filename, filesize, data, id, id, qsl("jpg"), peerId, photo, photoThumbs, MTP_documentEmpty(MTP_long(0)), jpeg, 0);
|
||||
|
||||
connect(App::uploader(), SIGNAL(photoReady(const FullMsgId&,bool,const MTPInputFile&)), App::app(), SLOT(photoUpdated(const FullMsgId&,bool,const MTPInputFile&)), Qt::UniqueConnection);
|
||||
|
||||
FullMsgId newId(peerToChannel(peerId), clientMsgId());
|
||||
App::app()->regPhotoUpdate(peerId, newId);
|
||||
App::uploader()->uploadMedia(newId, ready);
|
||||
}
|
||||
|
||||
void AppClass::checkMapVersion() {
|
||||
if (Local::oldMapVersion() < AppVersion) {
|
||||
if (Local::oldMapVersion()) {
|
||||
QString versionFeatures;
|
||||
if ((cAlphaVersion() || cBetaVersion()) && Local::oldMapVersion() < 1000010) {
|
||||
versionFeatures = QString::fromUtf8("\xe2\x80\x94 Support for more emoji.\n\xe2\x80\x94 Bug fixes and other minor improvements.");
|
||||
} else if (!(cAlphaVersion() || cBetaVersion()) && Local::oldMapVersion() < 1000012) {
|
||||
versionFeatures = langNewVersionText();
|
||||
} else {
|
||||
versionFeatures = lang(lng_new_version_minor).trimmed();
|
||||
}
|
||||
if (!versionFeatures.isEmpty()) {
|
||||
versionFeatures = lng_new_version_wrap(lt_version, QString::fromLatin1(AppVersionStr.c_str()), lt_changes, versionFeatures, lt_link, qsl("https://desktop.telegram.org/changelog"));
|
||||
_window->serviceNotificationLocal(versionFeatures);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppClass::joinThreads() {
|
||||
MTP::finish();
|
||||
}
|
||||
|
||||
AppClass::~AppClass() {
|
||||
Shortcuts::finish();
|
||||
|
||||
delete base::take(_window);
|
||||
App::clearHistories();
|
||||
|
||||
Window::Notifications::finish();
|
||||
|
||||
anim::stopManager();
|
||||
|
||||
stopWebLoadManager();
|
||||
App::deinitMedia();
|
||||
deinitLocationManager();
|
||||
|
||||
AppObject = nullptr;
|
||||
delete base::take(_uploader);
|
||||
delete base::take(_translator);
|
||||
|
||||
Window::Theme::Unload();
|
||||
|
||||
Media::Player::finish();
|
||||
style::stopManager();
|
||||
|
||||
Local::finish();
|
||||
Global::finish();
|
||||
ThirdParty::finish();
|
||||
}
|
||||
|
||||
AppClass *AppClass::app() {
|
||||
return AppObject;
|
||||
}
|
||||
|
||||
MainWindow *AppClass::wnd() {
|
||||
return AppObject ? AppObject->_window : nullptr;
|
||||
}
|
||||
|
||||
MainWidget *AppClass::main() {
|
||||
return (AppObject && AppObject->_window) ? AppObject->_window->mainWidget() : nullptr;
|
||||
}
|
||||
} // namespace Sandbox
|
||||
|
|
|
@ -20,17 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "pspecific.h"
|
||||
#include "core/single_timer.h"
|
||||
#include "core/observer.h"
|
||||
|
||||
namespace MTP {
|
||||
class DcOptions;
|
||||
} // namespace MTP
|
||||
|
||||
class AuthSession;
|
||||
|
||||
class UpdateChecker;
|
||||
class Application : public QApplication {
|
||||
Q_OBJECT
|
||||
|
@ -40,6 +29,13 @@ public:
|
|||
|
||||
bool event(QEvent *e) override;
|
||||
|
||||
void createMessenger();
|
||||
|
||||
~Application();
|
||||
|
||||
signals:
|
||||
void adjustSingleTimers();
|
||||
|
||||
// Single instance application
|
||||
public slots:
|
||||
void socketConnected();
|
||||
|
@ -61,6 +57,8 @@ private:
|
|||
typedef QPair<QLocalSocket*, QByteArray> LocalClient;
|
||||
typedef QList<LocalClient> LocalClients;
|
||||
|
||||
std::unique_ptr<Messenger> _messengerInstance;
|
||||
|
||||
QString _localServerName, _localSocketReadData;
|
||||
QLocalServer _localServer;
|
||||
QLocalSocket _localSocket;
|
||||
|
@ -102,7 +100,7 @@ public slots:
|
|||
void onUpdateFailed();
|
||||
|
||||
private:
|
||||
SingleTimer _updateCheckTimer;
|
||||
object_ptr<SingleTimer> _updateCheckTimer = { nullptr };
|
||||
QNetworkReply *_updateReply = nullptr;
|
||||
QNetworkAccessManager _updateManager;
|
||||
QThread *_updateThread = nullptr;
|
||||
|
@ -113,135 +111,34 @@ private:
|
|||
|
||||
namespace Sandbox {
|
||||
|
||||
QRect availableGeometry();
|
||||
QRect screenGeometry(const QPoint &p);
|
||||
void setActiveWindow(QWidget *window);
|
||||
bool isSavingSession();
|
||||
QRect availableGeometry();
|
||||
QRect screenGeometry(const QPoint &p);
|
||||
void setActiveWindow(QWidget *window);
|
||||
bool isSavingSession();
|
||||
|
||||
void installEventFilter(QObject *filter);
|
||||
void removeEventFilter(QObject *filter);
|
||||
void execExternal(const QString &cmd);
|
||||
|
||||
void execExternal(const QString &cmd);
|
||||
void adjustSingleTimers();
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
||||
|
||||
void startUpdateCheck();
|
||||
void stopUpdate();
|
||||
void startUpdateCheck();
|
||||
void stopUpdate();
|
||||
|
||||
Application::UpdatingState updatingState();
|
||||
int32 updatingSize();
|
||||
int32 updatingReady();
|
||||
Application::UpdatingState updatingState();
|
||||
int32 updatingSize();
|
||||
int32 updatingReady();
|
||||
|
||||
void updateChecking();
|
||||
void updateLatest();
|
||||
void updateProgress(qint64 ready, qint64 total);
|
||||
void updateFailed();
|
||||
void updateReady();
|
||||
void updateChecking();
|
||||
void updateLatest();
|
||||
void updateProgress(qint64 ready, qint64 total);
|
||||
void updateFailed();
|
||||
void updateReady();
|
||||
|
||||
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
|
||||
|
||||
void connect(const char *signal, QObject *object, const char *method);
|
||||
void connect(const char *signal, QObject *object, const char *method);
|
||||
|
||||
void launch();
|
||||
void launch();
|
||||
|
||||
}
|
||||
|
||||
class MainWidget;
|
||||
class FileUploader;
|
||||
class Translator;
|
||||
|
||||
class AppClass : public QObject, public RPCSender, private base::Subscriber {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AppClass();
|
||||
AppClass(const AppClass &other) = delete;
|
||||
AppClass &operator=(const AppClass &other) = delete;
|
||||
|
||||
void joinThreads();
|
||||
~AppClass();
|
||||
|
||||
static AppClass *app();
|
||||
static MainWindow *wnd();
|
||||
static MainWidget *main();
|
||||
|
||||
static AppClass &Instance() {
|
||||
auto result = app();
|
||||
t_assert(result != nullptr);
|
||||
return *result;
|
||||
}
|
||||
|
||||
MTP::DcOptions *dcOptions() {
|
||||
return _dcOptions.get();
|
||||
}
|
||||
AuthSession *authSession() {
|
||||
return _authSession.get();
|
||||
}
|
||||
void authSessionCreate(UserId userId);
|
||||
void authSessionDestroy();
|
||||
|
||||
FileUploader *uploader();
|
||||
void uploadProfilePhoto(const QImage &tosend, const PeerId &peerId);
|
||||
void regPhotoUpdate(const PeerId &peer, const FullMsgId &msgId);
|
||||
bool isPhotoUpdating(const PeerId &peer);
|
||||
void cancelPhotoUpdate(const PeerId &peer);
|
||||
|
||||
void selfPhotoCleared(const MTPUserProfilePhoto &result);
|
||||
void chatPhotoCleared(PeerId peer, const MTPUpdates &updates);
|
||||
void selfPhotoDone(const MTPphotos_Photo &result);
|
||||
void chatPhotoDone(PeerId peerId, const MTPUpdates &updates);
|
||||
bool peerPhotoFail(PeerId peerId, const RPCError &e);
|
||||
void peerClearPhoto(PeerId peer);
|
||||
|
||||
void writeUserConfigIn(TimeMs ms);
|
||||
|
||||
void killDownloadSessionsStart(int32 dc);
|
||||
void killDownloadSessionsStop(int32 dc);
|
||||
|
||||
void checkLocalTime();
|
||||
void checkMapVersion();
|
||||
|
||||
void handleAppActivated();
|
||||
void handleAppDeactivated();
|
||||
|
||||
signals:
|
||||
void peerPhotoDone(PeerId peer);
|
||||
void peerPhotoFail(PeerId peer);
|
||||
|
||||
void adjustSingleTimers();
|
||||
|
||||
public slots:
|
||||
void photoUpdated(const FullMsgId &msgId, bool silent, const MTPInputFile &file);
|
||||
|
||||
void onSwitchDebugMode();
|
||||
void onSwitchWorkMode();
|
||||
void onSwitchTestMode();
|
||||
|
||||
void killDownloadSessions();
|
||||
void onAppStateChanged(Qt::ApplicationState state);
|
||||
|
||||
void call_handleHistoryUpdate();
|
||||
void call_handleUnreadCounterUpdate();
|
||||
void call_handleFileDialogQueue();
|
||||
void call_handleDelayedPeerUpdates();
|
||||
void call_handleObservables();
|
||||
|
||||
private:
|
||||
void startLocalStorage();
|
||||
void loadLanguage();
|
||||
|
||||
QMap<FullMsgId, PeerId> photoUpdates;
|
||||
|
||||
QMap<int32, TimeMs> killDownloadSessionTimes;
|
||||
SingleTimer killDownloadSessionsTimer;
|
||||
|
||||
TimeMs _lastActionTime = 0;
|
||||
|
||||
MainWindow *_window = nullptr;
|
||||
FileUploader *_uploader = nullptr;
|
||||
Translator *_translator = nullptr;
|
||||
|
||||
std::unique_ptr<MTP::DcOptions> _dcOptions;
|
||||
std::unique_ptr<AuthSession> _authSession;
|
||||
|
||||
};
|
||||
} // namespace Sandbox
|
||||
|
|
|
@ -21,14 +21,14 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "stdafx.h"
|
||||
#include "auth_session.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
|
||||
AuthSession::AuthSession(UserId userId) : _userId(userId) {
|
||||
t_assert(_userId != 0);
|
||||
}
|
||||
|
||||
AuthSession *AuthSession::Current() {
|
||||
return AppClass::Instance().authSession();
|
||||
return Messenger::Instance().authSession();
|
||||
}
|
||||
|
||||
UserData *AuthSession::CurrentUser() {
|
||||
|
|
|
@ -88,34 +88,6 @@ void AboutBox::keyPressEvent(QKeyEvent *e) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
|
||||
QString _getCrashReportFile(const QMimeData *m) {
|
||||
if (!m || m->urls().size() != 1 || !m->urls().at(0).isLocalFile()) return QString();
|
||||
|
||||
auto file = Platform::FileDialog::UrlToLocal(m->urls().at(0));
|
||||
|
||||
return file.endsWith(qstr(".telegramcrash"), Qt::CaseInsensitive) ? file : QString();
|
||||
}
|
||||
#endif // !TDESKTOP_DISABLE_CRASH_REPORTS
|
||||
|
||||
void AboutBox::dragEnterEvent(QDragEnterEvent *e) {
|
||||
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
|
||||
if (!_getCrashReportFile(e->mimeData()).isEmpty()) {
|
||||
e->setDropAction(Qt::CopyAction);
|
||||
e->accept();
|
||||
}
|
||||
#endif // !TDESKTOP_DISABLE_CRASH_REPORTS
|
||||
}
|
||||
|
||||
void AboutBox::dropEvent(QDropEvent *e) {
|
||||
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
|
||||
if (!_getCrashReportFile(e->mimeData()).isEmpty()) {
|
||||
e->acceptProposedAction();
|
||||
showCrashReportWindow(_getCrashReportFile(e->mimeData()));
|
||||
}
|
||||
#endif // !TDESKTOP_DISABLE_CRASH_REPORTS
|
||||
}
|
||||
|
||||
QString telegramFaqLink() {
|
||||
QString result = qsl("https://telegram.org/faq");
|
||||
if (cLang() > languageDefault && cLang() < languageCount) {
|
||||
|
|
|
@ -36,8 +36,6 @@ protected:
|
|||
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
void dragEnterEvent(QDragEnterEvent *e) override;
|
||||
void dropEvent(QDropEvent *e) override;
|
||||
|
||||
private:
|
||||
void showVersionHistory();
|
||||
|
|
|
@ -24,7 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_dialogs.h"
|
||||
#include "lang.h"
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
#include "boxes/contactsbox.h"
|
||||
#include "boxes/confirmbox.h"
|
||||
#include "boxes/photocropbox.h"
|
||||
|
@ -541,7 +541,7 @@ void SetupChannelBox::mouseMoveEvent(QMouseEvent *e) {
|
|||
|
||||
void SetupChannelBox::mousePressEvent(QMouseEvent *e) {
|
||||
if (_linkOver) {
|
||||
Application::clipboard()->setText(_channel->inviteLink());
|
||||
QGuiApplication::clipboard()->setText(_channel->inviteLink());
|
||||
Ui::Toast::Show(lang(lng_create_channel_link_copied));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "boxes/addcontactbox.h"
|
||||
#include "mainwidget.h"
|
||||
#include "mainwindow.h"
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/filedialog.h"
|
||||
|
|
|
@ -27,7 +27,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_dialogs.h"
|
||||
#include "styles/style_window.h"
|
||||
#include "application.h"
|
||||
#include "mainwindow.h"
|
||||
#include "localstorage.h"
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -22,7 +22,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "boxes/photocropbox.h"
|
||||
|
||||
#include "lang.h"
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
#include "mainwidget.h"
|
||||
#include "photocropbox.h"
|
||||
#include "fileuploader.h"
|
||||
|
|
|
@ -25,10 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
|
||||
SingleTimer::SingleTimer(QObject *parent) : QTimer(parent) {
|
||||
QTimer::setSingleShot(true);
|
||||
if (App::app()) {
|
||||
connect(App::app(), SIGNAL(adjustSingleTimers()), this, SLOT(adjust()));
|
||||
_inited = true;
|
||||
}
|
||||
Sandbox::connect(SIGNAL(adjustSingleTimers()), this, SLOT(adjust()));
|
||||
}
|
||||
|
||||
void SingleTimer::setTimeoutHandler(base::lambda<void()> &&handler) {
|
||||
|
@ -59,10 +56,6 @@ void SingleTimer::onTimeout() {
|
|||
|
||||
void SingleTimer::start(int msec) {
|
||||
_finishing = getms(true) + (msec < 0 ? 0 : msec);
|
||||
if (!_inited && App::app()) {
|
||||
connect(App::app(), SIGNAL(adjustSingleTimers()), this, SLOT(adjust()));
|
||||
_inited = true;
|
||||
}
|
||||
QTimer::start(msec);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ private slots:
|
|||
|
||||
private:
|
||||
TimeMs _finishing = 0;
|
||||
bool _inited = false;
|
||||
base::lambda<void()> _handler;
|
||||
|
||||
};
|
||||
|
|
|
@ -35,6 +35,7 @@ extern "C" {
|
|||
}
|
||||
|
||||
#include "application.h"
|
||||
#include "pspecific.h"
|
||||
|
||||
uint64 _SharedMemoryLocation[4] = { 0x00, 0x01, 0x02, 0x03 };
|
||||
|
||||
|
@ -320,7 +321,6 @@ namespace ThirdParty {
|
|||
|
||||
Platform::ThirdParty::finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool checkms() {
|
||||
|
@ -330,7 +330,7 @@ bool checkms() {
|
|||
_msAddToUnixtime = ((ms - unixms) / 1000LL) * 1000LL;
|
||||
} else if (unixms > ms + 1000LL) {
|
||||
_msAddToMsStart += ((unixms - ms) / 1000LL) * 1000LL;
|
||||
if (App::app()) emit App::app()->adjustSingleTimers();
|
||||
Sandbox::adjustSingleTimers();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -25,7 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "observer_peer.h"
|
||||
#include "mainwindow.h"
|
||||
#include "mainwidget.h"
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
#include "boxes/confirmbox.h"
|
||||
#include "layerwidget.h"
|
||||
#include "lang.h"
|
||||
|
|
|
@ -31,6 +31,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "intro/intropwdcheck.h"
|
||||
#include "mainwidget.h"
|
||||
#include "mainwindow.h"
|
||||
#include "messenger.h"
|
||||
#include "application.h"
|
||||
#include "boxes/confirmbox.h"
|
||||
#include "ui/text/text.h"
|
||||
|
|
|
@ -34,6 +34,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "media/media_audio.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
#include "mtproto/dc_options.h"
|
||||
#include "messenger.h"
|
||||
#include "application.h"
|
||||
#include "apiwrap.h"
|
||||
#include "auth_session.h"
|
||||
|
@ -837,7 +838,7 @@ struct ReadSettingsContext {
|
|||
};
|
||||
|
||||
void applyReadContext(const ReadSettingsContext &context) {
|
||||
AppClass::Instance().dcOptions()->addFromOther(context.dcOptions);
|
||||
Messenger::Instance().dcOptions()->addFromOther(context.dcOptions);
|
||||
}
|
||||
|
||||
bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSettingsContext &context) {
|
||||
|
@ -911,7 +912,7 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
|
|||
MTP::configure(dcId);
|
||||
|
||||
if (userId) {
|
||||
AppClass::Instance().authSessionCreate(UserId(userId));
|
||||
Messenger::Instance().authSessionCreate(UserId(userId));
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -2238,7 +2239,7 @@ void writeSettings() {
|
|||
}
|
||||
settings.writeData(_settingsSalt);
|
||||
|
||||
auto dcOptionsSerialized = AppClass::Instance().dcOptions()->serialize();
|
||||
auto dcOptionsSerialized = Messenger::Instance().dcOptions()->serialize();
|
||||
|
||||
quint32 size = 12 * (sizeof(quint32) + sizeof(qint32));
|
||||
size += sizeof(quint32) + Serialize::bytearraySize(dcOptionsSerialized);
|
||||
|
|
|
@ -35,10 +35,6 @@ int main(int argc, char *argv[]) {
|
|||
return psFixPrevious();
|
||||
} else if (cLaunchMode() == LaunchModeCleanup) {
|
||||
return psCleanup();
|
||||
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
|
||||
} else if (cLaunchMode() == LaunchModeShowCrash) {
|
||||
return showCrashReportWindow(QFileInfo(cStartUrl()).absoluteFilePath());
|
||||
#endif // !TDESKTOP_DISABLE_CRASH_REPORTS
|
||||
}
|
||||
|
||||
// both are finished in Application::closeApplication
|
||||
|
|
|
@ -39,6 +39,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "lang.h"
|
||||
#include "boxes/addcontactbox.h"
|
||||
#include "fileuploader.h"
|
||||
#include "messenger.h"
|
||||
#include "application.h"
|
||||
#include "mainwindow.h"
|
||||
#include "inline_bots/inline_bot_layout_item.h"
|
||||
|
@ -115,7 +116,7 @@ MainWidget::MainWidget(QWidget *parent) : TWidget(parent)
|
|||
updateDialogsWidthAnimated();
|
||||
});
|
||||
|
||||
Sandbox::installEventFilter(this);
|
||||
QCoreApplication::instance()->installEventFilter(this);
|
||||
|
||||
connect(&_updateMutedTimer, SIGNAL(timeout()), this, SLOT(onUpdateMuted()));
|
||||
connect(&_viewsIncrementTimer, SIGNAL(timeout()), this, SLOT(onViewsIncrement()));
|
||||
|
@ -3738,7 +3739,7 @@ void MainWidget::start(const MTPUser &user) {
|
|||
return;
|
||||
}
|
||||
if (AuthSession::CurrentUserId() != uid) {
|
||||
AppClass::Instance().authSessionCreate(uid);
|
||||
Messenger::Instance().authSessionCreate(uid);
|
||||
Local::writeMtpData();
|
||||
}
|
||||
|
||||
|
@ -4916,7 +4917,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
|
|||
|
||||
case mtpc_updateDcOptions: {
|
||||
auto &d = update.c_updateDcOptions();
|
||||
AppClass::Instance().dcOptions()->addFromList(d.vdc_options);
|
||||
Messenger::Instance().dcOptions()->addFromList(d.vdc_options);
|
||||
} break;
|
||||
|
||||
case mtpc_updateUserPhone: {
|
||||
|
|
|
@ -30,6 +30,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "core/zlib_help.h"
|
||||
#include "lang.h"
|
||||
#include "shortcuts.h"
|
||||
#include "messenger.h"
|
||||
#include "application.h"
|
||||
#include "pspecific.h"
|
||||
#include "passcodewidget.h"
|
||||
|
@ -165,7 +166,7 @@ void MainWindow::onStateChanged(Qt::WindowState state) {
|
|||
void MainWindow::initHook() {
|
||||
Platform::MainWindow::initHook();
|
||||
|
||||
Application::instance()->installEventFilter(this);
|
||||
QCoreApplication::instance()->installEventFilter(this);
|
||||
connect(windowHandle(), SIGNAL(windowStateChanged(Qt::WindowState)), this, SLOT(onStateChanged(Qt::WindowState)));
|
||||
connect(windowHandle(), SIGNAL(activeChanged()), this, SLOT(onWindowActiveChanged()), Qt::QueuedConnection);
|
||||
}
|
||||
|
@ -636,14 +637,14 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *e) {
|
|||
break;
|
||||
|
||||
case QEvent::ApplicationActivate:
|
||||
if (obj == Application::instance()) {
|
||||
if (obj == QCoreApplication::instance()) {
|
||||
psUserActionDone();
|
||||
QTimer::singleShot(1, this, SLOT(onWindowActiveChanged()));
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::FileOpen:
|
||||
if (obj == Application::instance()) {
|
||||
if (obj == QCoreApplication::instance()) {
|
||||
QString url = static_cast<QFileOpenEvent*>(e)->url().toEncoded().trimmed();
|
||||
if (url.startsWith(qstr("tg://"), Qt::CaseInsensitive)) {
|
||||
cSetStartUrl(url.mid(0, 8192));
|
||||
|
@ -2409,47 +2410,3 @@ void NetworkSettingsWindow::updateControls() {
|
|||
setGeometry(_parent->x() + (_parent->width() - w) / 2, _parent->y() + (_parent->height() - h) / 2, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
ShowCrashReportWindow::ShowCrashReportWindow(const QString &text)
|
||||
: _log(this) {
|
||||
_log.setPlainText(text);
|
||||
|
||||
QRect scr(QApplication::primaryScreen()->availableGeometry());
|
||||
setGeometry(scr.x() + (scr.width() / 6), scr.y() + (scr.height() / 6), scr.width() / 2, scr.height() / 2);
|
||||
show();
|
||||
}
|
||||
|
||||
void ShowCrashReportWindow::resizeEvent(QResizeEvent *e) {
|
||||
_log.setGeometry(rect().marginsRemoved(QMargins(basicSize(), basicSize(), basicSize(), basicSize())));
|
||||
}
|
||||
|
||||
void ShowCrashReportWindow::closeEvent(QCloseEvent *e) {
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
|
||||
int showCrashReportWindow(const QString &crashdump) {
|
||||
QString text;
|
||||
|
||||
QFile dump(crashdump);
|
||||
if (dump.open(QIODevice::ReadOnly)) {
|
||||
text = qsl("Crash dump file '%1':\n\n").arg(QFileInfo(crashdump).absoluteFilePath());
|
||||
text += psPrepareCrashDump(dump.readAll(), crashdump);
|
||||
} else {
|
||||
text = qsl("ERROR: could not read crash dump file '%1'").arg(QFileInfo(crashdump).absoluteFilePath());
|
||||
}
|
||||
|
||||
if (Global::started()) {
|
||||
ShowCrashReportWindow *wnd = new ShowCrashReportWindow(text);
|
||||
return 0;
|
||||
}
|
||||
|
||||
QByteArray args[] = { QFile::encodeName(QDir::toNativeSeparators(cExeDir() + cExeName())) };
|
||||
int a_argc = 1;
|
||||
char *a_argv[1] = { args[0].data() };
|
||||
QApplication app(a_argc, a_argv);
|
||||
|
||||
ShowCrashReportWindow *wnd = new ShowCrashReportWindow(text);
|
||||
return app.exec();
|
||||
}
|
||||
#endif // !TDESKTOP_DISABLE_CRASH_REPORTS
|
||||
|
|
|
@ -479,7 +479,3 @@ private:
|
|||
PreLaunchLog _log;
|
||||
|
||||
};
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_CRASH_REPORTS
|
||||
int showCrashReportWindow(const QString &crashdump);
|
||||
#endif // !TDESKTOP_DISABLE_CRASH_REPORTS
|
||||
|
|
|
@ -2651,9 +2651,9 @@ void MediaView::setVisible(bool visible) {
|
|||
}
|
||||
TWidget::setVisible(visible);
|
||||
if (visible) {
|
||||
Sandbox::installEventFilter(this);
|
||||
QCoreApplication::instance()->installEventFilter(this);
|
||||
} else {
|
||||
Sandbox::removeEventFilter(this);
|
||||
QCoreApplication::instance()->removeEventFilter(this);
|
||||
|
||||
stopGif();
|
||||
destroyThemePreview();
|
||||
|
|
|
@ -0,0 +1,536 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop version of Telegram messaging app, see https://telegram.org
|
||||
|
||||
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.
|
||||
|
||||
In addition, as a special exception, the copyright holders give permission
|
||||
to link the code of portions of this program with the OpenSSL library.
|
||||
|
||||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
||||
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include "messenger.h"
|
||||
|
||||
#include "localstorage.h"
|
||||
#include "pspecific.h"
|
||||
#include "mainwindow.h"
|
||||
#include "application.h"
|
||||
#include "shortcuts.h"
|
||||
#include "auth_session.h"
|
||||
#include "langloaderplain.h"
|
||||
#include "observer_peer.h"
|
||||
#include "fileuploader.h"
|
||||
#include "mainwidget.h"
|
||||
#include "mtproto/dc_options.h"
|
||||
#include "media/player/media_player_instance.h"
|
||||
#include "window/notifications_manager.h"
|
||||
#include "window/themes/window_theme.h"
|
||||
#include "history/history_location_manager.h"
|
||||
#include "ui/widgets/tooltip.h"
|
||||
#include "ui/filedialog.h"
|
||||
|
||||
namespace {
|
||||
|
||||
Messenger *SingleInstance = nullptr;
|
||||
|
||||
void mtpStateChanged(int32 dc, int32 state) {
|
||||
if (App::wnd()) {
|
||||
App::wnd()->mtpStateChanged(dc, state);
|
||||
}
|
||||
}
|
||||
|
||||
void mtpSessionReset(int32 dc) {
|
||||
if (App::main() && dc == MTP::maindc()) {
|
||||
App::main()->getDifference();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Messenger *Messenger::InstancePointer() {
|
||||
return SingleInstance;
|
||||
}
|
||||
|
||||
Messenger::Messenger() : QObject() {
|
||||
t_assert(SingleInstance == nullptr);
|
||||
SingleInstance = this;
|
||||
|
||||
Fonts::start();
|
||||
|
||||
ThirdParty::start();
|
||||
Global::start();
|
||||
|
||||
startLocalStorage();
|
||||
|
||||
if (Local::oldSettingsVersion() < AppVersion) {
|
||||
psNewVersion();
|
||||
}
|
||||
|
||||
if (cLaunchMode() == LaunchModeAutoStart && !cAutoStart()) {
|
||||
psAutoStart(false, true);
|
||||
App::quit();
|
||||
return;
|
||||
}
|
||||
|
||||
if (cRetina()) {
|
||||
cSetConfigScale(dbisOne);
|
||||
cSetRealScale(dbisOne);
|
||||
}
|
||||
loadLanguage();
|
||||
style::startManager();
|
||||
anim::startManager();
|
||||
historyInit();
|
||||
Media::Player::start();
|
||||
Window::Notifications::start();
|
||||
|
||||
DEBUG_LOG(("Application Info: inited..."));
|
||||
|
||||
QCoreApplication::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.
|
||||
QMimeDatabase().mimeTypeForName(qsl("text/plain"));
|
||||
|
||||
_window = std::make_unique<MainWindow>();
|
||||
_window->createWinId();
|
||||
_window->init();
|
||||
|
||||
Sandbox::connect(SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onAppStateChanged(Qt::ApplicationState)));
|
||||
|
||||
DEBUG_LOG(("Application Info: window created..."));
|
||||
|
||||
Shortcuts::start();
|
||||
|
||||
initLocationManager();
|
||||
App::initMedia();
|
||||
|
||||
Local::ReadMapState state = Local::readMap(QByteArray());
|
||||
if (state == Local::ReadMapPassNeeded) {
|
||||
Global::SetLocalPasscode(true);
|
||||
Global::RefLocalPasscodeChanged().notify();
|
||||
DEBUG_LOG(("Application Info: passcode needed..."));
|
||||
} else {
|
||||
DEBUG_LOG(("Application Info: local map read..."));
|
||||
MTP::start();
|
||||
}
|
||||
|
||||
MTP::setStateChangedHandler(mtpStateChanged);
|
||||
MTP::setSessionResetHandler(mtpSessionReset);
|
||||
|
||||
DEBUG_LOG(("Application Info: MTP started..."));
|
||||
|
||||
DEBUG_LOG(("Application Info: showing."));
|
||||
if (state == Local::ReadMapPassNeeded) {
|
||||
_window->setupPasscode();
|
||||
} else {
|
||||
if (AuthSession::Current()) {
|
||||
_window->setupMain();
|
||||
} else {
|
||||
_window->setupIntro();
|
||||
}
|
||||
}
|
||||
_window->firstShow();
|
||||
|
||||
if (cStartToSettings()) {
|
||||
_window->showSettings();
|
||||
}
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
|
||||
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
||||
#endif // !TDESKTOP_DISABLE_NETWORK_PROXY
|
||||
|
||||
if (state != Local::ReadMapPassNeeded) {
|
||||
checkMapVersion();
|
||||
}
|
||||
|
||||
_window->updateIsActive(Global::OnlineFocusTimeout());
|
||||
|
||||
if (!Shortcuts::errors().isEmpty()) {
|
||||
const QStringList &errors(Shortcuts::errors());
|
||||
for (QStringList::const_iterator i = errors.cbegin(), e = errors.cend(); i != e; ++i) {
|
||||
LOG(("Shortcuts Error: %1").arg(*i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::loadLanguage() {
|
||||
if (cLang() < languageTest) {
|
||||
cSetLang(Sandbox::LangSystem());
|
||||
}
|
||||
if (cLang() == languageTest) {
|
||||
if (QFileInfo(cLangFile()).exists()) {
|
||||
LangLoaderPlain loader(cLangFile());
|
||||
cSetLangErrors(loader.errors());
|
||||
if (!cLangErrors().isEmpty()) {
|
||||
LOG(("Lang load errors: %1").arg(cLangErrors()));
|
||||
} else if (!loader.warnings().isEmpty()) {
|
||||
LOG(("Lang load warnings: %1").arg(loader.warnings()));
|
||||
}
|
||||
} else {
|
||||
cSetLang(languageDefault);
|
||||
}
|
||||
} else if (cLang() > languageDefault && cLang() < languageCount) {
|
||||
LangLoaderPlain loader(qsl(":/langs/lang_") + LanguageCodes[cLang()].c_str() + qsl(".strings"));
|
||||
if (!loader.errors().isEmpty()) {
|
||||
LOG(("Lang load errors: %1").arg(loader.errors()));
|
||||
} else if (!loader.warnings().isEmpty()) {
|
||||
LOG(("Lang load warnings: %1").arg(loader.warnings()));
|
||||
}
|
||||
}
|
||||
QCoreApplication::instance()->installTranslator(_translator = new Translator());
|
||||
}
|
||||
|
||||
void Messenger::startLocalStorage() {
|
||||
_dcOptions = std::make_unique<MTP::DcOptions>();
|
||||
_dcOptions->constructFromBuiltIn();
|
||||
Local::start();
|
||||
subscribe(_dcOptions->changed(), [](const MTP::DcOptions::Ids &ids) {
|
||||
Local::writeSettings();
|
||||
for (auto id : ids) {
|
||||
MTP::restart(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Messenger::regPhotoUpdate(const PeerId &peer, const FullMsgId &msgId) {
|
||||
photoUpdates.insert(msgId, peer);
|
||||
}
|
||||
|
||||
bool Messenger::isPhotoUpdating(const PeerId &peer) {
|
||||
for (QMap<FullMsgId, PeerId>::iterator i = photoUpdates.begin(), e = photoUpdates.end(); i != e; ++i) {
|
||||
if (i.value() == peer) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Messenger::cancelPhotoUpdate(const PeerId &peer) {
|
||||
for (QMap<FullMsgId, PeerId>::iterator i = photoUpdates.begin(), e = photoUpdates.end(); i != e;) {
|
||||
if (i.value() == peer) {
|
||||
i = photoUpdates.erase(i);
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::selfPhotoCleared(const MTPUserProfilePhoto &result) {
|
||||
if (!App::self()) return;
|
||||
App::self()->setPhoto(result);
|
||||
emit peerPhotoDone(App::self()->id);
|
||||
}
|
||||
|
||||
void Messenger::chatPhotoCleared(PeerId peer, const MTPUpdates &updates) {
|
||||
if (App::main()) {
|
||||
App::main()->sentUpdatesReceived(updates);
|
||||
}
|
||||
cancelPhotoUpdate(peer);
|
||||
emit peerPhotoDone(peer);
|
||||
}
|
||||
|
||||
void Messenger::selfPhotoDone(const MTPphotos_Photo &result) {
|
||||
if (!App::self()) return;
|
||||
const auto &photo(result.c_photos_photo());
|
||||
App::feedPhoto(photo.vphoto);
|
||||
App::feedUsers(photo.vusers);
|
||||
cancelPhotoUpdate(App::self()->id);
|
||||
emit peerPhotoDone(App::self()->id);
|
||||
}
|
||||
|
||||
void Messenger::chatPhotoDone(PeerId peer, const MTPUpdates &updates) {
|
||||
if (App::main()) {
|
||||
App::main()->sentUpdatesReceived(updates);
|
||||
}
|
||||
cancelPhotoUpdate(peer);
|
||||
emit peerPhotoDone(peer);
|
||||
}
|
||||
|
||||
bool Messenger::peerPhotoFail(PeerId peer, const RPCError &error) {
|
||||
if (MTP::isDefaultHandledError(error)) return false;
|
||||
|
||||
LOG(("Application Error: update photo failed %1: %2").arg(error.type()).arg(error.description()));
|
||||
cancelPhotoUpdate(peer);
|
||||
emit peerPhotoFail(peer);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Messenger::peerClearPhoto(PeerId id) {
|
||||
if (!AuthSession::Current()) return;
|
||||
|
||||
if (id == AuthSession::CurrentUserPeerId()) {
|
||||
MTP::send(MTPphotos_UpdateProfilePhoto(MTP_inputPhotoEmpty()), rpcDone(&Messenger::selfPhotoCleared), rpcFail(&Messenger::peerPhotoFail, id));
|
||||
} else if (peerIsChat(id)) {
|
||||
MTP::send(MTPmessages_EditChatPhoto(peerToBareMTPInt(id), MTP_inputChatPhotoEmpty()), rpcDone(&Messenger::chatPhotoCleared, id), rpcFail(&Messenger::peerPhotoFail, id));
|
||||
} else if (peerIsChannel(id)) {
|
||||
if (auto channel = App::channelLoaded(id)) {
|
||||
MTP::send(MTPchannels_EditPhoto(channel->inputChannel, MTP_inputChatPhotoEmpty()), rpcDone(&Messenger::chatPhotoCleared, id), rpcFail(&Messenger::peerPhotoFail, id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::killDownloadSessionsStart(int32 dc) {
|
||||
if (killDownloadSessionTimes.constFind(dc) == killDownloadSessionTimes.cend()) {
|
||||
killDownloadSessionTimes.insert(dc, getms() + MTPAckSendWaiting + MTPKillFileSessionTimeout);
|
||||
}
|
||||
if (!killDownloadSessionsTimer.isActive()) {
|
||||
killDownloadSessionsTimer.start(MTPAckSendWaiting + MTPKillFileSessionTimeout + 5);
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::killDownloadSessionsStop(int32 dc) {
|
||||
killDownloadSessionTimes.remove(dc);
|
||||
if (killDownloadSessionTimes.isEmpty() && killDownloadSessionsTimer.isActive()) {
|
||||
killDownloadSessionsTimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::checkLocalTime() {
|
||||
if (App::main()) App::main()->checkLastUpdate(checkms());
|
||||
}
|
||||
|
||||
void Messenger::onAppStateChanged(Qt::ApplicationState state) {
|
||||
if (state == Qt::ApplicationActive) {
|
||||
handleAppActivated();
|
||||
} else {
|
||||
handleAppDeactivated();
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::handleAppActivated() {
|
||||
checkLocalTime();
|
||||
if (_window) {
|
||||
_window->updateIsActive(Global::OnlineFocusTimeout());
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::handleAppDeactivated() {
|
||||
if (_window) {
|
||||
_window->updateIsActive(Global::OfflineBlurTimeout());
|
||||
}
|
||||
Ui::Tooltip::Hide();
|
||||
}
|
||||
|
||||
void Messenger::call_handleHistoryUpdate() {
|
||||
Notify::handlePendingHistoryUpdate();
|
||||
}
|
||||
|
||||
void Messenger::call_handleUnreadCounterUpdate() {
|
||||
Global::RefUnreadCounterUpdate().notify(true);
|
||||
}
|
||||
|
||||
void Messenger::call_handleFileDialogQueue() {
|
||||
while (true) {
|
||||
if (!FileDialog::processQuery()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::call_handleDelayedPeerUpdates() {
|
||||
Notify::peerUpdatedSendDelayed();
|
||||
}
|
||||
|
||||
void Messenger::call_handleObservables() {
|
||||
base::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 (int j = 0; j < MTPDownloadSessionsCount; ++j) {
|
||||
MTP::stopSession(MTP::dldDcId(i.key(), j));
|
||||
}
|
||||
i = killDownloadSessionTimes.erase(i);
|
||||
} else {
|
||||
if (i.value() - ms < left) {
|
||||
left = i.value() - ms;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
if (!killDownloadSessionTimes.isEmpty()) {
|
||||
killDownloadSessionsTimer.start(left);
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::photoUpdated(const FullMsgId &msgId, bool silent, const MTPInputFile &file) {
|
||||
if (!AuthSession::Current()) return;
|
||||
|
||||
auto i = photoUpdates.find(msgId);
|
||||
if (i != photoUpdates.end()) {
|
||||
auto id = i.value();
|
||||
if (id == AuthSession::CurrentUserPeerId()) {
|
||||
MTP::send(MTPphotos_UploadProfilePhoto(file), rpcDone(&Messenger::selfPhotoDone), rpcFail(&Messenger::peerPhotoFail, id));
|
||||
} else if (peerIsChat(id)) {
|
||||
auto history = App::history(id);
|
||||
history->sendRequestId = MTP::send(MTPmessages_EditChatPhoto(history->peer->asChat()->inputChat, MTP_inputChatUploadedPhoto(file)), rpcDone(&Messenger::chatPhotoDone, id), rpcFail(&Messenger::peerPhotoFail, id), 0, 0, history->sendRequestId);
|
||||
} else if (peerIsChannel(id)) {
|
||||
auto history = App::history(id);
|
||||
history->sendRequestId = MTP::send(MTPchannels_EditPhoto(history->peer->asChannel()->inputChannel, MTP_inputChatUploadedPhoto(file)), rpcDone(&Messenger::chatPhotoDone, id), rpcFail(&Messenger::peerPhotoFail, id), 0, 0, history->sendRequestId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::onSwitchDebugMode() {
|
||||
if (cDebug()) {
|
||||
QFile(cWorkingDir() + qsl("tdata/withdebug")).remove();
|
||||
cSetDebug(false);
|
||||
App::restart();
|
||||
} else {
|
||||
cSetDebug(true);
|
||||
DEBUG_LOG(("Debug logs started."));
|
||||
QFile f(cWorkingDir() + qsl("tdata/withdebug"));
|
||||
if (f.open(QIODevice::WriteOnly)) {
|
||||
f.write("1");
|
||||
f.close();
|
||||
}
|
||||
Ui::hideLayer();
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::onSwitchWorkMode() {
|
||||
Global::SetDialogsModeEnabled(!Global::DialogsModeEnabled());
|
||||
Global::SetDialogsMode(Dialogs::Mode::All);
|
||||
Local::writeUserSettings();
|
||||
App::restart();
|
||||
}
|
||||
|
||||
void Messenger::onSwitchTestMode() {
|
||||
if (cTestMode()) {
|
||||
QFile(cWorkingDir() + qsl("tdata/withtestmode")).remove();
|
||||
cSetTestMode(false);
|
||||
} else {
|
||||
QFile f(cWorkingDir() + qsl("tdata/withtestmode"));
|
||||
if (f.open(QIODevice::WriteOnly)) {
|
||||
f.write("1");
|
||||
f.close();
|
||||
}
|
||||
cSetTestMode(true);
|
||||
}
|
||||
App::restart();
|
||||
}
|
||||
|
||||
void Messenger::authSessionCreate(UserId userId) {
|
||||
_authSession = std::make_unique<AuthSession>(userId);
|
||||
}
|
||||
|
||||
void Messenger::authSessionDestroy() {
|
||||
_authSession.reset();
|
||||
}
|
||||
|
||||
FileUploader *Messenger::uploader() {
|
||||
if (!_uploader && !App::quitting()) _uploader = new FileUploader();
|
||||
return _uploader;
|
||||
}
|
||||
|
||||
void Messenger::uploadProfilePhoto(const QImage &tosend, const PeerId &peerId) {
|
||||
PreparedPhotoThumbs photoThumbs;
|
||||
QVector<MTPPhotoSize> photoSizes;
|
||||
|
||||
auto thumb = App::pixmapFromImageInPlace(tosend.scaled(160, 160, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
photoThumbs.insert('a', thumb);
|
||||
photoSizes.push_back(MTP_photoSize(MTP_string("a"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(thumb.width()), MTP_int(thumb.height()), MTP_int(0)));
|
||||
|
||||
auto medium = App::pixmapFromImageInPlace(tosend.scaled(320, 320, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
photoThumbs.insert('b', medium);
|
||||
photoSizes.push_back(MTP_photoSize(MTP_string("b"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(medium.width()), MTP_int(medium.height()), MTP_int(0)));
|
||||
|
||||
auto full = QPixmap::fromImage(tosend, Qt::ColorOnly);
|
||||
photoThumbs.insert('c', full);
|
||||
photoSizes.push_back(MTP_photoSize(MTP_string("c"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0)));
|
||||
|
||||
QByteArray jpeg;
|
||||
QBuffer jpegBuffer(&jpeg);
|
||||
full.save(&jpegBuffer, "JPG", 87);
|
||||
|
||||
PhotoId id = rand_value<PhotoId>();
|
||||
|
||||
MTPDphoto::Flags photoFlags = 0;
|
||||
auto photo = MTP_photo(MTP_flags(photoFlags), MTP_long(id), MTP_long(0), MTP_int(unixtime()), MTP_vector<MTPPhotoSize>(photoSizes));
|
||||
|
||||
QString file, filename;
|
||||
int32 filesize = 0;
|
||||
QByteArray data;
|
||||
|
||||
SendMediaReady ready(SendMediaType::Photo, file, filename, filesize, data, id, id, qsl("jpg"), peerId, photo, photoThumbs, MTP_documentEmpty(MTP_long(0)), jpeg, 0);
|
||||
|
||||
connect(App::uploader(), SIGNAL(photoReady(const FullMsgId&, bool, const MTPInputFile&)), App::app(), SLOT(photoUpdated(const FullMsgId&, bool, const MTPInputFile&)), Qt::UniqueConnection);
|
||||
|
||||
FullMsgId newId(peerToChannel(peerId), clientMsgId());
|
||||
App::app()->regPhotoUpdate(peerId, newId);
|
||||
App::uploader()->uploadMedia(newId, ready);
|
||||
}
|
||||
|
||||
void Messenger::checkMapVersion() {
|
||||
if (Local::oldMapVersion() < AppVersion) {
|
||||
if (Local::oldMapVersion()) {
|
||||
QString versionFeatures;
|
||||
if ((cAlphaVersion() || cBetaVersion()) && Local::oldMapVersion() < 1000010) {
|
||||
versionFeatures = QString::fromUtf8("\xe2\x80\x94 Support for more emoji.\n\xe2\x80\x94 Bug fixes and other minor improvements.");
|
||||
} else if (!(cAlphaVersion() || cBetaVersion()) && Local::oldMapVersion() < 1000012) {
|
||||
versionFeatures = langNewVersionText();
|
||||
} else {
|
||||
versionFeatures = lang(lng_new_version_minor).trimmed();
|
||||
}
|
||||
if (!versionFeatures.isEmpty()) {
|
||||
versionFeatures = lng_new_version_wrap(lt_version, QString::fromLatin1(AppVersionStr.c_str()), lt_changes, versionFeatures, lt_link, qsl("https://desktop.telegram.org/changelog"));
|
||||
_window->serviceNotificationLocal(versionFeatures);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Messenger::prepareToDestroy() {
|
||||
_window.reset();
|
||||
MTP::finish();
|
||||
}
|
||||
|
||||
Messenger::~Messenger() {
|
||||
t_assert(SingleInstance == this);
|
||||
SingleInstance = nullptr;
|
||||
|
||||
Shortcuts::finish();
|
||||
|
||||
App::clearHistories();
|
||||
|
||||
Window::Notifications::finish();
|
||||
|
||||
anim::stopManager();
|
||||
|
||||
stopWebLoadManager();
|
||||
App::deinitMedia();
|
||||
deinitLocationManager();
|
||||
|
||||
delete base::take(_uploader);
|
||||
delete base::take(_translator);
|
||||
|
||||
Window::Theme::Unload();
|
||||
|
||||
Media::Player::finish();
|
||||
style::stopManager();
|
||||
|
||||
Local::finish();
|
||||
Global::finish();
|
||||
ThirdParty::finish();
|
||||
}
|
||||
|
||||
MainWindow *Messenger::mainWindow() {
|
||||
return _window.get();
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop version of Telegram messaging app, see https://telegram.org
|
||||
|
||||
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.
|
||||
|
||||
In addition, as a special exception, the copyright holders give permission
|
||||
to link the code of portions of this program with the OpenSSL library.
|
||||
|
||||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
||||
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "core/observer.h"
|
||||
|
||||
namespace MTP {
|
||||
class DcOptions;
|
||||
} // namespace MTP
|
||||
|
||||
class AuthSession;
|
||||
class MainWidget;
|
||||
class FileUploader;
|
||||
class Translator;
|
||||
|
||||
class Messenger : public QObject, public RPCSender, private base::Subscriber {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Messenger();
|
||||
|
||||
Messenger(const Messenger &other) = delete;
|
||||
Messenger &operator=(const Messenger &other) = delete;
|
||||
|
||||
void prepareToDestroy();
|
||||
~Messenger();
|
||||
|
||||
MainWindow *mainWindow();
|
||||
|
||||
static Messenger *InstancePointer();
|
||||
static Messenger &Instance() {
|
||||
auto result = InstancePointer();
|
||||
t_assert(result != nullptr);
|
||||
return *result;
|
||||
}
|
||||
|
||||
MTP::DcOptions *dcOptions() {
|
||||
return _dcOptions.get();
|
||||
}
|
||||
AuthSession *authSession() {
|
||||
return _authSession.get();
|
||||
}
|
||||
void authSessionCreate(UserId userId);
|
||||
void authSessionDestroy();
|
||||
|
||||
FileUploader *uploader();
|
||||
void uploadProfilePhoto(const QImage &tosend, const PeerId &peerId);
|
||||
void regPhotoUpdate(const PeerId &peer, const FullMsgId &msgId);
|
||||
bool isPhotoUpdating(const PeerId &peer);
|
||||
void cancelPhotoUpdate(const PeerId &peer);
|
||||
|
||||
void selfPhotoCleared(const MTPUserProfilePhoto &result);
|
||||
void chatPhotoCleared(PeerId peer, const MTPUpdates &updates);
|
||||
void selfPhotoDone(const MTPphotos_Photo &result);
|
||||
void chatPhotoDone(PeerId peerId, const MTPUpdates &updates);
|
||||
bool peerPhotoFail(PeerId peerId, const RPCError &e);
|
||||
void peerClearPhoto(PeerId peer);
|
||||
|
||||
void writeUserConfigIn(TimeMs ms);
|
||||
|
||||
void killDownloadSessionsStart(int32 dc);
|
||||
void killDownloadSessionsStop(int32 dc);
|
||||
|
||||
void checkLocalTime();
|
||||
void checkMapVersion();
|
||||
|
||||
void handleAppActivated();
|
||||
void handleAppDeactivated();
|
||||
|
||||
signals:
|
||||
void peerPhotoDone(PeerId peer);
|
||||
void peerPhotoFail(PeerId peer);
|
||||
|
||||
public slots:
|
||||
void photoUpdated(const FullMsgId &msgId, bool silent, const MTPInputFile &file);
|
||||
|
||||
void onSwitchDebugMode();
|
||||
void onSwitchWorkMode();
|
||||
void onSwitchTestMode();
|
||||
|
||||
void killDownloadSessions();
|
||||
void onAppStateChanged(Qt::ApplicationState state);
|
||||
|
||||
void call_handleHistoryUpdate();
|
||||
void call_handleUnreadCounterUpdate();
|
||||
void call_handleFileDialogQueue();
|
||||
void call_handleDelayedPeerUpdates();
|
||||
void call_handleObservables();
|
||||
|
||||
private:
|
||||
void startLocalStorage();
|
||||
void loadLanguage();
|
||||
|
||||
QMap<FullMsgId, PeerId> photoUpdates;
|
||||
|
||||
QMap<int32, TimeMs> killDownloadSessionTimes;
|
||||
SingleTimer killDownloadSessionsTimer;
|
||||
|
||||
TimeMs _lastActionTime = 0;
|
||||
|
||||
std::unique_ptr<MainWindow> _window;
|
||||
FileUploader *_uploader = nullptr;
|
||||
Translator *_translator = nullptr;
|
||||
|
||||
std::unique_ptr<MTP::DcOptions> _dcOptions;
|
||||
std::unique_ptr<AuthSession> _authSession;
|
||||
|
||||
};
|
|
@ -32,7 +32,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "lang.h"
|
||||
|
||||
#include "mtproto/rsa_public_key.h"
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
#include "mtproto/dc_options.h"
|
||||
#include "mtproto/connection_abstract.h"
|
||||
|
||||
|
@ -457,7 +457,7 @@ ConnectionPrivate::ConnectionPrivate(QThread *thread, Connection *owner, Session
|
|||
moveToThread(thread);
|
||||
|
||||
if (!dc) {
|
||||
dc = AppClass::Instance().dcOptions()->getDefaultDcId();
|
||||
dc = Messenger::Instance().dcOptions()->getDefaultDcId();
|
||||
DEBUG_LOG(("MTP Info: searching for any DC, %1 selected...").arg(dc));
|
||||
}
|
||||
|
||||
|
@ -1093,7 +1093,7 @@ void ConnectionPrivate::socketStart(bool afterConfig) {
|
|||
auto kIPv6 = Variants::IPv6;
|
||||
auto kTcp = Variants::Tcp;
|
||||
auto kHttp = Variants::Http;
|
||||
auto variants = AppClass::Instance().dcOptions()->lookup(bareDcId(dc), dcType);
|
||||
auto variants = Messenger::Instance().dcOptions()->lookup(bareDcId(dc), dcType);
|
||||
auto noIPv4 = (variants.data[kIPv4][kHttp].port == 0);
|
||||
auto noIPv6 = (!Global::TryIPv6() || (variants.data[kIPv6][kHttp].port == 0));
|
||||
if (noIPv4 && noIPv6) {
|
||||
|
|
|
@ -23,7 +23,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
|
||||
#include "mtproto/facade.h"
|
||||
#include "mtproto/dc_options.h"
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
#include "localstorage.h"
|
||||
|
||||
namespace MTP {
|
||||
|
@ -152,7 +152,7 @@ void configLoaded(const MTPConfig &result) {
|
|||
if (data.vdc_options.c_vector().v.empty()) {
|
||||
LOG(("MTP Error: config with empty dc_options received!"));
|
||||
} else {
|
||||
AppClass::Instance().dcOptions()->setFromList(data.vdc_options);
|
||||
Messenger::Instance().dcOptions()->setFromList(data.vdc_options);
|
||||
}
|
||||
|
||||
Global::SetChatSizeMax(data.vchat_size_max.v);
|
||||
|
@ -224,7 +224,7 @@ void ConfigLoader::enumDC() {
|
|||
} else {
|
||||
MTP::killSession(MTP::cfgDcId(_enumCurrent));
|
||||
}
|
||||
auto ids = AppClass::Instance().dcOptions()->sortedDcIds();
|
||||
auto ids = Messenger::Instance().dcOptions()->sortedDcIds();
|
||||
t_assert(!ids.empty());
|
||||
|
||||
auto i = std::find(ids.cbegin(), ids.cend(), _enumCurrent);
|
||||
|
|
|
@ -19,13 +19,11 @@ Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|||
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "mtproto/file_download.h"
|
||||
|
||||
#include "mainwidget.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
#include "localstorage.h"
|
||||
|
||||
namespace {
|
||||
|
@ -559,8 +557,8 @@ void mtpFileLoader::cancelRequests() {
|
|||
_queue->queries -= _requests.size();
|
||||
_requests.clear();
|
||||
|
||||
if (!_queue->queries && App::app()) {
|
||||
App::app()->killDownloadSessionsStart(_dc);
|
||||
if (!_queue->queries) {
|
||||
Messenger::Instance().killDownloadSessionsStart(_dc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "lang.h"
|
||||
#include "localstorage.h"
|
||||
#include "mainwindow.h"
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
#include "ui/text/text.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
|
|
|
@ -36,7 +36,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "apiwrap.h"
|
||||
#include "mainwidget.h"
|
||||
#include "mainwindow.h"
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
#include "platform/platform_file_dialog.h"
|
||||
|
||||
namespace Profile {
|
||||
|
@ -107,10 +107,8 @@ void CoverWidget::onPhotoShow() {
|
|||
}
|
||||
|
||||
void CoverWidget::onCancelPhotoUpload() {
|
||||
if (auto app = App::app()) {
|
||||
app->cancelPhotoUpdate(_peer->id);
|
||||
refreshStatusText();
|
||||
}
|
||||
Messenger::Instance().cancelPhotoUpdate(_peer->id);
|
||||
refreshStatusText();
|
||||
}
|
||||
|
||||
int CoverWidget::countPhotoLeft(int newWidth) const {
|
||||
|
@ -359,19 +357,17 @@ void CoverWidget::refreshNameText() {
|
|||
}
|
||||
|
||||
void CoverWidget::refreshStatusText() {
|
||||
if (auto app = App::app()) {
|
||||
if (app->isPhotoUpdating(_peer->id)) {
|
||||
_statusText = lang(lng_settings_uploading_photo);
|
||||
_statusTextIsOnline = false;
|
||||
if (!_cancelPhotoUpload) {
|
||||
_cancelPhotoUpload.create(this, lang(lng_cancel), st::defaultLinkButton);
|
||||
connect(_cancelPhotoUpload, SIGNAL(clicked()), this, SLOT(onCancelPhotoUpload()));
|
||||
_cancelPhotoUpload->show();
|
||||
_cancelPhotoUpload->moveToLeft(_statusPosition.x() + st::profileStatusFont->width(_statusText) + st::profileStatusFont->spacew, _statusPosition.y());
|
||||
}
|
||||
update();
|
||||
return;
|
||||
if (Messenger::Instance().isPhotoUpdating(_peer->id)) {
|
||||
_statusText = lang(lng_settings_uploading_photo);
|
||||
_statusTextIsOnline = false;
|
||||
if (!_cancelPhotoUpload) {
|
||||
_cancelPhotoUpload.create(this, lang(lng_cancel), st::defaultLinkButton);
|
||||
connect(_cancelPhotoUpload, SIGNAL(clicked()), this, SLOT(onCancelPhotoUpload()));
|
||||
_cancelPhotoUpload->show();
|
||||
_cancelPhotoUpload->moveToLeft(_statusPosition.x() + st::profileStatusFont->width(_statusText) + st::profileStatusFont->spacew, _statusPosition.y());
|
||||
}
|
||||
update();
|
||||
return;
|
||||
}
|
||||
|
||||
_cancelPhotoUpload.destroy();
|
||||
|
|
|
@ -30,21 +30,23 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include <execinfo.h>
|
||||
|
||||
namespace {
|
||||
QStringList _initLogs;
|
||||
|
||||
class _PsEventFilter : public QAbstractNativeEventFilter {
|
||||
public:
|
||||
_PsEventFilter() {
|
||||
}
|
||||
QStringList _initLogs;
|
||||
|
||||
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) {
|
||||
auto wnd = AppClass::wnd();
|
||||
if (!wnd) return false;
|
||||
class _PsEventFilter : public QAbstractNativeEventFilter {
|
||||
public:
|
||||
_PsEventFilter() {
|
||||
}
|
||||
|
||||
return wnd->psFilterNativeEvent(message);
|
||||
}
|
||||
};
|
||||
_PsEventFilter *_psEventFilter = 0;
|
||||
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) {
|
||||
auto wnd = App::wnd();
|
||||
if (!wnd) return false;
|
||||
|
||||
return wnd->psFilterNativeEvent(message);
|
||||
}
|
||||
};
|
||||
|
||||
_PsEventFilter *_psEventFilter = nullptr;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
|
||||
#include "mainwindow.h"
|
||||
#include "mainwidget.h"
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
#include "localstorage.h"
|
||||
#include "media/player/media_player_instance.h"
|
||||
#include "media/media_audio.h"
|
||||
|
@ -121,8 +121,8 @@ ApplicationDelegate *_sharedDelegate = nil;
|
|||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)aNotification {
|
||||
if (App::app()) {
|
||||
App::app()->handleAppActivated();
|
||||
if (auto messenger = Messenger::InstancePointer()) {
|
||||
messenger->handleAppActivated();
|
||||
if (auto window = App::wnd()) {
|
||||
if (window->isHidden()) {
|
||||
window->showFromTray();
|
||||
|
@ -132,8 +132,8 @@ ApplicationDelegate *_sharedDelegate = nil;
|
|||
}
|
||||
|
||||
- (void)receiveWakeNote:(NSNotification*)aNotification {
|
||||
if (App::app()) {
|
||||
App::app()->checkLocalTime();
|
||||
if (auto messenger = Messenger::InstancePointer()) {
|
||||
messenger->checkLocalTime();
|
||||
}
|
||||
|
||||
LOG(("Audio Info: -receiveWakeNote: received, scheduling detach from audio device"));
|
||||
|
|
|
@ -27,7 +27,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "platform/win/windows_dlls.h"
|
||||
#include "platform/win/windows_event_filter.h"
|
||||
#include "lang.h"
|
||||
#include "application.h"
|
||||
#include "mainwindow.h"
|
||||
#include "mainwidget.h"
|
||||
#include "history/history_location_manager.h"
|
||||
|
||||
|
|
|
@ -181,10 +181,6 @@ void settingsParseArgs(int argc, char *argv[]) {
|
|||
|
||||
gExeDir = psCurrentExeDirectory(argc, argv);
|
||||
gExeName = psCurrentExeName(argc, argv);
|
||||
if (argc == 2 && fromUtf8Safe(argv[1]).endsWith(qstr(".telegramcrash")) && QFile(fromUtf8Safe(argv[1])).exists()) {
|
||||
gLaunchMode = LaunchModeShowCrash;
|
||||
gStartUrl = fromUtf8Safe(argv[1]);
|
||||
}
|
||||
for (int32 i = 0; i < argc; ++i) {
|
||||
if (qstr("-testmode") == argv[i]) {
|
||||
gTestMode = true;
|
||||
|
@ -200,9 +196,6 @@ void settingsParseArgs(int argc, char *argv[]) {
|
|||
gLaunchMode = LaunchModeFixPrevious;
|
||||
} else if (qstr("-cleanup") == argv[i]) {
|
||||
gLaunchMode = LaunchModeCleanup;
|
||||
} else if (qstr("-crash") == argv[i] && i + 1 < argc) {
|
||||
gLaunchMode = LaunchModeShowCrash;
|
||||
gStartUrl = fromUtf8Safe(argv[++i]);
|
||||
} else if (qstr("-noupdate") == argv[i]) {
|
||||
gNoStartUpdate = true;
|
||||
} else if (qstr("-tosettings") == argv[i]) {
|
||||
|
|
|
@ -75,7 +75,6 @@ enum LaunchMode {
|
|||
LaunchModeAutoStart,
|
||||
LaunchModeFixPrevious,
|
||||
LaunchModeCleanup,
|
||||
LaunchModeShowCrash,
|
||||
};
|
||||
DeclareReadSetting(LaunchMode, LaunchMode);
|
||||
DeclareSetting(QString, WorkingDir);
|
||||
|
|
|
@ -25,7 +25,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "ui/widgets/buttons.h"
|
||||
#include "observer_peer.h"
|
||||
#include "lang.h"
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
#include "mainwindow.h"
|
||||
#include "apiwrap.h"
|
||||
#include "profile/profile_userpic_button.h"
|
||||
#include "profile/profile_cover_drop_area.h"
|
||||
|
@ -91,10 +92,8 @@ void CoverWidget::onPhotoShow() {
|
|||
}
|
||||
|
||||
void CoverWidget::onCancelPhotoUpload() {
|
||||
if (auto app = App::app()) {
|
||||
app->cancelPhotoUpdate(_self->id);
|
||||
refreshStatusText();
|
||||
}
|
||||
Messenger::Instance().cancelPhotoUpdate(_self->id);
|
||||
refreshStatusText();
|
||||
}
|
||||
|
||||
int CoverWidget::resizeGetHeight(int newWidth) {
|
||||
|
@ -277,19 +276,17 @@ void CoverWidget::refreshNameText() {
|
|||
}
|
||||
|
||||
void CoverWidget::refreshStatusText() {
|
||||
if (auto app = App::app()) {
|
||||
if (app->isPhotoUpdating(_self->id)) {
|
||||
_statusText = lang(lng_settings_uploading_photo);
|
||||
_statusTextIsOnline = false;
|
||||
if (!_cancelPhotoUpload) {
|
||||
_cancelPhotoUpload.create(this, lang(lng_cancel), st::defaultLinkButton);
|
||||
connect(_cancelPhotoUpload, SIGNAL(clicked()), this, SLOT(onCancelPhotoUpload()));
|
||||
_cancelPhotoUpload->show();
|
||||
_cancelPhotoUpload->moveToLeft(_statusPosition.x() + st::settingsStatusFont->width(_statusText) + st::settingsStatusFont->spacew, _statusPosition.y());
|
||||
}
|
||||
update();
|
||||
return;
|
||||
if (Messenger::Instance().isPhotoUpdating(_self->id)) {
|
||||
_statusText = lang(lng_settings_uploading_photo);
|
||||
_statusTextIsOnline = false;
|
||||
if (!_cancelPhotoUpload) {
|
||||
_cancelPhotoUpload.create(this, lang(lng_cancel), st::defaultLinkButton);
|
||||
connect(_cancelPhotoUpload, SIGNAL(clicked()), this, SLOT(onCancelPhotoUpload()));
|
||||
_cancelPhotoUpload->show();
|
||||
_cancelPhotoUpload->moveToLeft(_statusPosition.x() + st::settingsStatusFont->width(_statusText) + st::settingsStatusFont->spacew, _statusPosition.y());
|
||||
}
|
||||
update();
|
||||
return;
|
||||
}
|
||||
|
||||
_cancelPhotoUpload.destroy();
|
||||
|
|
|
@ -34,7 +34,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "localstorage.h"
|
||||
#include "boxes/confirmbox.h"
|
||||
#include "lang.h"
|
||||
#include "application.h"
|
||||
#include "messenger.h"
|
||||
#include "ui/filedialog.h"
|
||||
#include "window/themes/window_theme.h"
|
||||
#include "window/themes/window_theme_editor.h"
|
||||
|
|
|
@ -21,7 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "stdafx.h"
|
||||
#include "ui/filedialog.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "mainwindow.h"
|
||||
#include "localstorage.h"
|
||||
#include "platform/platform_file_dialog.h"
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "stdafx.h"
|
||||
#include "ui/widgets/tooltip.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "mainwindow.h"
|
||||
#include "styles/style_widgets.h"
|
||||
|
||||
namespace Ui {
|
||||
|
@ -99,7 +99,7 @@ void Tooltip::popup(const QPoint &m, const QString &text, const style::Tooltip *
|
|||
_hideByLeaveTimer.setSingleShot(true);
|
||||
connect(&_hideByLeaveTimer, SIGNAL(timeout()), this, SLOT(onHideByLeave()));
|
||||
|
||||
Sandbox::installEventFilter(this);
|
||||
QCoreApplication::instance()->installEventFilter(this);
|
||||
}
|
||||
|
||||
_point = m;
|
||||
|
|
|
@ -748,7 +748,7 @@ void Notification::showReplyField() {
|
|||
_replyArea->setCtrlEnterSubmit(Ui::CtrlEnterSubmit::Both);
|
||||
|
||||
// Catch mouse press event to activate the window.
|
||||
Sandbox::installEventFilter(this);
|
||||
QCoreApplication::instance()->installEventFilter(this);
|
||||
connect(_replyArea, SIGNAL(resized()), this, SLOT(onReplyResize()));
|
||||
connect(_replyArea, SIGNAL(submitted(bool)), this, SLOT(onReplySubmit(bool)));
|
||||
connect(_replyArea, SIGNAL(cancelled()), this, SLOT(onReplyCancel()));
|
||||
|
|
|
@ -145,6 +145,8 @@
|
|||
'<(src_loc)/localstorage.h',
|
||||
'<(src_loc)/logs.cpp',
|
||||
'<(src_loc)/logs.h',
|
||||
'<(src_loc)/messenger.cpp',
|
||||
'<(src_loc)/messenger.h',
|
||||
'<(src_loc)/mainwidget.cpp',
|
||||
'<(src_loc)/mainwidget.h',
|
||||
'<(src_loc)/settings.cpp',
|
||||
|
|
Loading…
Reference in New Issue