From e122353bfbaf93506f0c0d08b05946fbefb88e87 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 3 Jun 2018 22:52:23 +0300 Subject: [PATCH] Show better information in sessions list. --- Telegram/SourceFiles/boxes/sessions_box.cpp | 6 +- Telegram/SourceFiles/config.h | 19 ------ Telegram/SourceFiles/core/launcher.cpp | 22 +++++- Telegram/SourceFiles/core/launcher.h | 17 +++-- Telegram/SourceFiles/mtproto/connection.cpp | 6 +- .../platform/linux/launcher_linux.cpp | 19 ++++++ .../platform/linux/launcher_linux.h | 2 +- .../SourceFiles/platform/mac/launcher_mac.h | 2 +- .../SourceFiles/platform/mac/launcher_mac.mm | 68 +++++++++++++++++++ .../SourceFiles/platform/platform_launcher.h | 2 +- .../SourceFiles/platform/win/launcher_win.cpp | 24 +++++++ .../SourceFiles/platform/win/launcher_win.h | 2 +- 12 files changed, 155 insertions(+), 34 deletions(-) diff --git a/Telegram/SourceFiles/boxes/sessions_box.cpp b/Telegram/SourceFiles/boxes/sessions_box.cpp index 05c9cef13..a2fc235e5 100644 --- a/Telegram/SourceFiles/boxes/sessions_box.cpp +++ b/Telegram/SourceFiles/boxes/sessions_box.cpp @@ -28,15 +28,15 @@ void SessionsBox::prepare() { setDimensions(st::boxWideWidth, st::sessionsHeight); + _inner = setInnerWidget(object_ptr(this, &_list, &_current), st::sessionsScroll); + _inner->resize(width(), st::noContactsHeight); + connect(_inner, SIGNAL(oneTerminated()), this, SLOT(onOneTerminated())); connect(_inner, SIGNAL(allTerminated()), this, SLOT(onAllTerminated())); connect(_inner, SIGNAL(terminateAll()), this, SLOT(onTerminateAll())); connect(App::wnd(), SIGNAL(checkNewAuthorization()), this, SLOT(onCheckNewAuthorization())); connect(_shortPollTimer, SIGNAL(timeout()), this, SLOT(onShortPollAuthorizations())); - _inner = setInnerWidget(object_ptr(this, &_list, &_current), st::sessionsScroll); - _inner->resize(width(), st::noContactsHeight); - setLoading(true); MTP::send(MTPaccount_GetAuthorizations(), rpcDone(&SessionsBox::gotAuthorizations)); diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index ac4bd2549..120218d70 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -222,25 +222,6 @@ static const char *ApiHash = "344583e45741c457fe1862106095a5eb"; static const char *BetaPrivateKey = ""; #endif -inline const char *cApiDeviceModel() { -#ifdef Q_OS_WIN - return "PC"; -#elif defined Q_OS_MAC - return "Mac"; -#elif defined Q_OS_LINUX - return "PC"; -#endif -} -inline const char *cApiSystemVersion() { -#ifdef Q_OS_WIN - return "Windows"; -#elif defined Q_OS_MAC - return "OS X"; -#elif defined Q_OS_LINUX - return "Linux"; -#endif -} - extern QString gKeyFile; inline const QString &cDataFile() { if (!gKeyFile.isEmpty()) return gKeyFile; diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index 62662277b..e2d500f61 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -19,9 +19,15 @@ std::unique_ptr Launcher::Create(int argc, char *argv[]) { return std::make_unique(argc, argv); } -Launcher::Launcher(int argc, char *argv[]) +Launcher::Launcher( + int argc, + char *argv[], + const QString &deviceModel, + const QString &systemVersion) : _argc(argc) -, _argv(argv) { +, _argv(argv) +, _deviceModel(deviceModel) +, _systemVersion(systemVersion) { } void Launcher::init() { @@ -94,6 +100,10 @@ QString Launcher::argumentsString() const { return _arguments.join(' '); } +bool Launcher::customWorkingDir() const { + return _customWorkingDir; +} + void Launcher::prepareSettings() { #ifdef Q_OS_MAC #ifndef OS_MAC_OLD @@ -152,6 +162,14 @@ void Launcher::prepareSettings() { processArguments(); } +QString Launcher::deviceModel() const { + return _deviceModel; +} + +QString Launcher::systemVersion() const { + return _systemVersion; +} + void Launcher::processArguments() { enum class KeyFormat { NoValues, diff --git a/Telegram/SourceFiles/core/launcher.h b/Telegram/SourceFiles/core/launcher.h index f42e79d1f..54575749c 100644 --- a/Telegram/SourceFiles/core/launcher.h +++ b/Telegram/SourceFiles/core/launcher.h @@ -11,16 +11,22 @@ namespace Core { class Launcher { public: - Launcher(int argc, char *argv[]); + Launcher( + int argc, + char *argv[], + const QString &deviceModel, + const QString &systemVersion); static std::unique_ptr Create(int argc, char *argv[]); int exec(); QString argumentsString() const; - bool customWorkingDir() const { - return _customWorkingDir; - } + bool customWorkingDir() const; + + // Thread safe. + QString deviceModel() const; + QString systemVersion() const; virtual ~Launcher() = default; @@ -53,6 +59,9 @@ private: char **_argv; QStringList _arguments; + const QString _deviceModel; + const QString _systemVersion; + bool _customWorkingDir = false; }; diff --git a/Telegram/SourceFiles/mtproto/connection.cpp b/Telegram/SourceFiles/mtproto/connection.cpp index 3515d93e8..c9cbe3f83 100644 --- a/Telegram/SourceFiles/mtproto/connection.cpp +++ b/Telegram/SourceFiles/mtproto/connection.cpp @@ -13,6 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/dc_options.h" #include "mtproto/connection_abstract.h" #include "zlib.h" +#include "messenger.h" +#include "core/launcher.h" #include "lang/lang_keys.h" #include "base/openssl_help.h" #include "base/qthelp_url.h" @@ -822,10 +824,10 @@ void ConnectionPrivate::tryToSend() { const auto langPack = "tdesktop"; const auto deviceModel = (_dcType == DcType::Cdn) ? "n/a" - : cApiDeviceModel(); + : Messenger::Instance().launcher()->deviceModel(); const auto systemVersion = (_dcType == DcType::Cdn) ? "n/a" - : cApiSystemVersion(); + : Messenger::Instance().launcher()->systemVersion(); const auto proxyType = _connectionOptions->proxy.type; const auto mtprotoProxy = (proxyType == ProxyData::Type::Mtproto); const auto clientProxyFields = mtprotoProxy diff --git a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp index dbfe0e9cb..c3cb6830a 100644 --- a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp @@ -38,8 +38,27 @@ private: }; +QString DeviceModel() { +#ifdef Q_OS_LINUX64 + return "PC 64bit"; +#else // Q_OS_LINUX64 + return "PC 32bit"; +#endif // Q_OS_LINUX64 +} + +QString SystemVersion() { + const auto result = getenv("XDG_CURRENT_DESKTOP"); + const auto value = result ? QString::fromLatin1(result) : QString(); + const auto list = value.split(':', QString::SkipEmptyParts); + return list.isEmpty() ? "Linux" : "Linux " + list[0]; +} + } // namespace +Launcher::Launcher(int argc, char *argv[]) +: Core::Launcher(argc, argv, DeviceModel(), SystemVersion()) { +} + bool Launcher::launchUpdater(UpdaterLaunch action) { if (cExeName().isEmpty()) { return false; diff --git a/Telegram/SourceFiles/platform/linux/launcher_linux.h b/Telegram/SourceFiles/platform/linux/launcher_linux.h index db1de2817..0b7dea131 100644 --- a/Telegram/SourceFiles/platform/linux/launcher_linux.h +++ b/Telegram/SourceFiles/platform/linux/launcher_linux.h @@ -13,7 +13,7 @@ namespace Platform { class Launcher : public Core::Launcher { public: - using Core::Launcher::Launcher; + Launcher(int argc, char *argv[]); private: bool launchUpdater(UpdaterLaunch action) override; diff --git a/Telegram/SourceFiles/platform/mac/launcher_mac.h b/Telegram/SourceFiles/platform/mac/launcher_mac.h index 0ef15457c..edb966a01 100644 --- a/Telegram/SourceFiles/platform/mac/launcher_mac.h +++ b/Telegram/SourceFiles/platform/mac/launcher_mac.h @@ -13,7 +13,7 @@ namespace Platform { class Launcher : public Core::Launcher { public: - using Core::Launcher::Launcher; + Launcher(int argc, char *argv[]); private: void initHook() override; diff --git a/Telegram/SourceFiles/platform/mac/launcher_mac.mm b/Telegram/SourceFiles/platform/mac/launcher_mac.mm index d562b8bf6..6f8c480fd 100644 --- a/Telegram/SourceFiles/platform/mac/launcher_mac.mm +++ b/Telegram/SourceFiles/platform/mac/launcher_mac.mm @@ -12,8 +12,76 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include +#include namespace Platform { +namespace { + +QString FromIdentifier(const QString &model) { + if (model.isEmpty() || model.toLower().indexOf("mac") < 0) { + return QString(); + } + QStringList words; + QString word; + for (const QChar ch : model) { + if (!ch.isLetter()) { + continue; + } + if (ch.isUpper()) { + if (!word.isEmpty()) { + words.push_back(word); + word = QString(); + } + } + word.append(ch); + } + if (!word.isEmpty()) { + words.push_back(word); + } + QString result; + for (const QString word : words) { + if (!result.isEmpty() + && word != "Mac" + && word != "Book") { + result.append(' '); + } + result.append(word); + } + return result; +} + +QString DeviceModel() { + size_t length = 0; + sysctlbyname("hw.model", nullptr, &length, nullptr, 0); + if (length > 0) { + QByteArray bytes(length, Qt::Uninitialized); + sysctlbyname("hw.model", bytes.data(), &length, nullptr, 0); + const QString parsed = FromIdentifier(QString::fromUtf8(bytes)); + if (!parsed.isEmpty()) { + return parsed; + } + } + return "Mac"; +} + +QString SystemVersion() { + const int version = QSysInfo::macVersion(); + constexpr int kShift = 2; + if (version == QSysInfo::MV_None + || version == QSysInfo::MV_Unknown + || version < kShift + 6) { + return "OS X"; + } else if (version < kShift + 12) { + return QString("OS X 10.%1").arg(version - kShift); + } + return QString("macOS 10.%1").arg(version - kShift); +} + +} // namespace + +Launcher::Launcher(int argc, char *argv[]) +: Core::Launcher(argc, argv, DeviceModel(), SystemVersion()) { +} void Launcher::initHook() { #ifndef OS_MAC_OLD diff --git a/Telegram/SourceFiles/platform/platform_launcher.h b/Telegram/SourceFiles/platform/platform_launcher.h index 08ef90901..27180d00b 100644 --- a/Telegram/SourceFiles/platform/platform_launcher.h +++ b/Telegram/SourceFiles/platform/platform_launcher.h @@ -11,7 +11,7 @@ namespace Platform { //class Launcher : public Core::Launcher { //public: -// using Core::Launcher::Launcher; +// Launcher(int argc, char *argv[]); // // ... // diff --git a/Telegram/SourceFiles/platform/win/launcher_win.cpp b/Telegram/SourceFiles/platform/win/launcher_win.cpp index 95fd8632d..9ceabde01 100644 --- a/Telegram/SourceFiles/platform/win/launcher_win.cpp +++ b/Telegram/SourceFiles/platform/win/launcher_win.cpp @@ -14,6 +14,30 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include namespace Platform { +namespace { + +QString DeviceModel() { + return "PC"; +} + +QString SystemVersion() { + switch (QSysInfo::windowsVersion()) { + case QSysInfo::WV_XP: return "Windows XP"; + case QSysInfo::WV_2003: return "Windows 2003"; + case QSysInfo::WV_VISTA: return "Windows Vista"; + case QSysInfo::WV_WINDOWS7: return "Windows 7"; + case QSysInfo::WV_WINDOWS8: return "Windows 8"; + case QSysInfo::WV_WINDOWS8_1: return "Windows 8.1"; + case QSysInfo::WV_WINDOWS10: return "Windows 10"; + default: return "Windows"; + } +} + +} // namespace + +Launcher::Launcher(int argc, char *argv[]) +: Core::Launcher(argc, argv, DeviceModel(), SystemVersion()) { +} base::optional Launcher::readArgumentsHook( int argc, diff --git a/Telegram/SourceFiles/platform/win/launcher_win.h b/Telegram/SourceFiles/platform/win/launcher_win.h index 4cc852f87..49811bf65 100644 --- a/Telegram/SourceFiles/platform/win/launcher_win.h +++ b/Telegram/SourceFiles/platform/win/launcher_win.h @@ -13,7 +13,7 @@ namespace Platform { class Launcher : public Core::Launcher { public: - using Core::Launcher::Launcher; + Launcher(int argc, char *argv[]); private: base::optional readArgumentsHook(