diff --git a/Telegram/SourceFiles/boxes/about_box.cpp b/Telegram/SourceFiles/boxes/about_box.cpp index fe0093fb2c..a254125c91 100644 --- a/Telegram/SourceFiles/boxes/about_box.cpp +++ b/Telegram/SourceFiles/boxes/about_box.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/labels.h" #include "styles/style_boxes.h" #include "platform/platform_file_utilities.h" +#include "platform/platform_info.h" #include "core/click_handler_types.h" #include "core/update_checker.h" @@ -60,12 +61,18 @@ void AboutBox::resizeEvent(QResizeEvent *e) { void AboutBox::showVersionHistory() { if (cRealAlphaVersion()) { auto url = qsl("https://tdesktop.com/"); - switch (cPlatform()) { - case dbipWindows: url += qsl("win/%1.zip"); break; - case dbipMac: url += qsl("mac/%1.zip"); break; - case dbipMacOld: url += qsl("mac32/%1.zip"); break; - case dbipLinux32: url += qsl("linux32/%1.tar.xz"); break; - case dbipLinux64: url += qsl("linux/%1.tar.xz"); break; + if (Platform::IsWindows()) { + url += qsl("win/%1.zip"); + } else if (Platform::IsMacOldBuild()) { + url += qsl("mac32/%1.zip"); + } else if (Platform::IsMac()) { + url += qsl("mac/%1.zip"); + } else if (Platform::IsLinux32Bit()) { + url += qsl("linux32/%1.tar.xz"); + } else if (Platform::IsLinux64Bit()) { + url += qsl("linux/%1.tar.xz"); + } else { + Unexpected("Platform value."); } url = url.arg(qsl("talpha%1_%2").arg(cRealAlphaVersion()).arg(Core::countAlphaVersionSignature(cRealAlphaVersion()))); diff --git a/Telegram/SourceFiles/boxes/edit_color_box.cpp b/Telegram/SourceFiles/boxes/edit_color_box.cpp index 549c3c3f54..f6625a5b75 100644 --- a/Telegram/SourceFiles/boxes/edit_color_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_color_box.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "styles/style_boxes.h" #include "ui/widgets/shadow.h" +#include "platform/platform_info.h" #include "styles/style_mediaview.h" #include "ui/widgets/input_fields.h" @@ -517,7 +518,7 @@ void EditColorBox::Field::wheelEvent(QWheelEvent *e) { } auto deltaX = e->angleDelta().x(), deltaY = e->angleDelta().y(); - if (cPlatform() == dbipMac || cPlatform() == dbipMacOld) { + if (Platform::IsMac()) { deltaY *= -1; } else { deltaX *= -1; diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index c22c5d513d..07ba64da15 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/openssl_help.h" #include "mtproto/connection.h" #include "media/audio/media_audio_track.h" +#include "platform/platform_info.h" #include "calls/calls_panel.h" #include "data/data_user.h" #include "data/data_session.h" @@ -561,11 +562,7 @@ void Call::createAndStartController(const MTPDphoneCall &call) { tgvoip::VoIPController::Config config; config.dataSaving = tgvoip::DATA_SAVING_NEVER; -#ifdef Q_OS_MAC - config.enableAEC = (QSysInfo::macVersion() < QSysInfo::MV_10_7); -#else // Q_OS_MAC - config.enableAEC = true; -#endif // Q_OS_MAC + config.enableAEC = !Platform::IsMac10_7OrGreater(); config.enableNS = true; config.enableAGC = true; config.enableVolumeControl = true; diff --git a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp index e6049e5e83..1908ac137a 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp @@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_instance.h" #include "lang/lang_cloud_manager.h" #include "core/application.h" -#include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "ui/emoji_config.h" #include "auth_session.h" #include "apiwrap.h" diff --git a/Telegram/SourceFiles/core/crash_report_window.cpp b/Telegram/SourceFiles/core/crash_report_window.cpp index c7be123150..9d410f31b6 100644 --- a/Telegram/SourceFiles/core/crash_report_window.cpp +++ b/Telegram/SourceFiles/core/crash_report_window.cpp @@ -461,7 +461,7 @@ void LastCrashedWindow::onSendReport() { } QString apiid = getReportField(qstr("apiid"), qstr("ApiId:")), version = getReportField(qstr("version"), qstr("Version:")); - _checkReply = _sendManager.get(QNetworkRequest(qsl("https://tdesktop.com/crash.php?act=query_report&apiid=%1&version=%2&dmp=%3&platform=%4").arg(apiid).arg(version).arg(minidumpFileName().isEmpty() ? 0 : 1).arg(cPlatformString()))); + _checkReply = _sendManager.get(QNetworkRequest(qsl("https://tdesktop.com/crash.php?act=query_report&apiid=%1&version=%2&dmp=%3&platform=%4").arg(apiid).arg(version).arg(minidumpFileName().isEmpty() ? 0 : 1).arg(CrashReports::PlatformString()))); connect(_checkReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onSendingError(QNetworkReply::NetworkError))); connect(_checkReply, SIGNAL(finished()), this, SLOT(onCheckingFinished())); diff --git a/Telegram/SourceFiles/core/crash_reports.cpp b/Telegram/SourceFiles/core/crash_reports.cpp index 633820be96..ce938a3fa6 100644 --- a/Telegram/SourceFiles/core/crash_reports.cpp +++ b/Telegram/SourceFiles/core/crash_reports.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/crash_reports.h" #include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "core/launcher.h" #include @@ -320,13 +321,32 @@ bool DumpCallback(const google_breakpad::MinidumpDescriptor &md, void *context, } // namespace +QString PlatformString() { + if (Platform::IsWindowsStoreBuild()) { + return qsl("WinStore"); + } else if (Platform::IsWindows()) { + return qsl("Windows"); + } else if (Platform::IsMacStoreBuild()) { + return qsl("MacAppStore"); + } else if (Platform::IsMacOldBuild()) { + return qsl("MacOSold"); + } else if (Platform::IsMac()) { + return qsl("MacOS"); + } else if (Platform::IsLinux32Bit()) { + return qsl("Linux32Bit"); + } else if (Platform::IsLinux64Bit()) { + return qsl("Linux64bit"); + } + Unexpected("Platform in CrashReports::PlatformString."); +} + void StartCatching(not_null launcher) { #ifndef TDESKTOP_DISABLE_CRASH_REPORTS ProcessAnnotations["Binary"] = cExeName().toUtf8().constData(); ProcessAnnotations["ApiId"] = QString::number(ApiId).toUtf8().constData(); ProcessAnnotations["Version"] = (cAlphaVersion() ? qsl("%1 alpha").arg(cAlphaVersion()) : (AppBetaVersion ? qsl("%1 beta") : qsl("%1")).arg(AppVersion)).toUtf8().constData(); ProcessAnnotations["Launched"] = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss").toUtf8().constData(); - ProcessAnnotations["Platform"] = cPlatformString().toUtf8().constData(); + ProcessAnnotations["Platform"] = PlatformString().toUtf8().constData(); ProcessAnnotations["UserTag"] = QString::number(launcher->installationTag(), 16).toUtf8().constData(); QString dumpspath = cWorkingDir() + qsl("tdata/dumps"); diff --git a/Telegram/SourceFiles/core/crash_reports.h b/Telegram/SourceFiles/core/crash_reports.h index aadc0180b5..5e60afd0e2 100644 --- a/Telegram/SourceFiles/core/crash_reports.h +++ b/Telegram/SourceFiles/core/crash_reports.h @@ -13,6 +13,8 @@ class Launcher; namespace CrashReports { +QString PlatformString(); + #ifndef TDESKTOP_DISABLE_CRASH_REPORTS struct dump { diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index 851ed591ef..1b8c4795e6 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_launcher.h" #include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "core/crash_reports.h" #include "core/main_queue_processor.h" #include "core/update_checker.h" @@ -334,44 +335,6 @@ bool Launcher::customWorkingDir() const { } void Launcher::prepareSettings() { -#ifdef Q_OS_MAC -#ifndef OS_MAC_OLD - if (QSysInfo::macVersion() >= QSysInfo::MV_10_11) { - gIsElCapitan = true; - } -#else // OS_MAC_OLD - if (QSysInfo::macVersion() < QSysInfo::MV_10_7) { - gIsSnowLeopard = true; - } -#endif // OS_MAC_OLD -#endif // Q_OS_MAC - - switch (cPlatform()) { - case dbipWindows: -#ifndef OS_WIN_STORE - gPlatformString = qsl("Windows"); -#else // OS_WIN_STORE - gPlatformString = qsl("WinStore"); -#endif // OS_WIN_STORE - break; - case dbipMac: -#ifndef OS_MAC_STORE - gPlatformString = qsl("MacOS"); -#else // OS_MAC_STORE - gPlatformString = qsl("MacAppStore"); -#endif // OS_MAC_STORE - break; - case dbipMacOld: - gPlatformString = qsl("MacOSold"); - break; - case dbipLinux64: - gPlatformString = qsl("Linux64bit"); - break; - case dbipLinux32: - gPlatformString = qsl("Linux32bit"); - break; - } - auto path = Platform::CurrentExecutablePath(_argc, _argv); LOG(("Executable path before check: %1").arg(path)); if (!path.isEmpty()) { diff --git a/Telegram/SourceFiles/core/sandbox.cpp b/Telegram/SourceFiles/core/sandbox.cpp index 73c2a62901..c02a282637 100644 --- a/Telegram/SourceFiles/core/sandbox.cpp +++ b/Telegram/SourceFiles/core/sandbox.cpp @@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "core/sandbox.h" -#include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "mainwidget.h" #include "mainwindow.h" #include "storage/localstorage.h" @@ -178,7 +178,7 @@ void Sandbox::setupScreenScale() { const auto ratio = devicePixelRatio(); if (ratio > 1.) { - if ((cPlatform() != dbipMac && cPlatform() != dbipMacOld) || (ratio != 2.)) { + if (!Platform::IsMac() || (ratio != 2.)) { LOG(("Found non-trivial Device Pixel Ratio: %1").arg(ratio)); 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")))); diff --git a/Telegram/SourceFiles/core/shortcuts.cpp b/Telegram/SourceFiles/core/shortcuts.cpp index 1859b3ffd4..702cc30264 100644 --- a/Telegram/SourceFiles/core/shortcuts.cpp +++ b/Telegram/SourceFiles/core/shortcuts.cpp @@ -11,7 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "core/application.h" #include "media/player/media_player_instance.h" -#include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "base/parse_helper.h" namespace Shortcuts { @@ -299,7 +299,7 @@ void Manager::fillDefaults() { set(qsl("alt+down"), Command::ChatNext); set(qsl("ctrl+pgup"), Command::ChatPrevious); set(qsl("alt+up"), Command::ChatPrevious); - if (cPlatform() == dbipMac || cPlatform() == dbipMacOld) { + if (Platform::IsMac()) { set(qsl("meta+tab"), Command::ChatNext); set(qsl("meta+shift+tab"), Command::ChatPrevious); set(qsl("meta+backtab"), Command::ChatPrevious); diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index 8aefb97d90..0d4c390d30 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "core/update_checker.h" -#include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "base/timer.h" #include "base/bytes.h" #include "storage/localstorage.h" @@ -495,14 +495,19 @@ bool ParseCommonMap( } const auto platforms = document.object(); const auto platform = [&] { - switch (cPlatform()) { - case dbipWindows: return "win"; - case dbipMac: return "mac"; - case dbipMacOld: return "mac32"; - case dbipLinux64: return "linux"; - case dbipLinux32: return "linux32"; + if (Platform::IsWindows()) { + return "win"; + } else if (Platform::IsMacOldBuild()) { + return "mac32"; + } else if (Platform::IsMac()) { + return "mac"; + } else if (Platform::IsLinux32Bit()) { + return "linux32"; + } else if (Platform::IsLinux64Bit()) { + return "linux"; + } else { + Unexpected("Platform in ParseCommonMap."); } - Unexpected("Platform in ParseCommonMap."); }(); const auto it = platforms.constFind(platform); if (it == platforms.constEnd()) { diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index 46267020a6..c5df62cb89 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -341,14 +341,6 @@ QNetworkProxy ToNetworkProxy(const ProxyData &proxy); static const int MatrixRowShift = 40000; -enum DBIPlatform { - dbipWindows = 0, - dbipMac = 1, - dbipLinux64 = 2, - dbipLinux32 = 3, - dbipMacOld = 4, -}; - enum DBIPeerReportSpamStatus { dbiprsNoButton = 0, // hidden, but not in the cloud settings yet dbiprsUnknown = 1, // contacts not loaded yet diff --git a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp index eb488fa3d5..96b927fffc 100644 --- a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp +++ b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp @@ -16,7 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "storage/localstorage.h" #include "core/file_utilities.h" -#include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "auth_session.h" #include "data/data_session.h" #include "styles/style_export.h" @@ -107,7 +107,7 @@ bool IsDefaultPath(const QString &path) { const auto result = value.endsWith('/') ? value.mid(0, value.size() - 1) : value; - return (cPlatform() == dbipWindows) ? result.toLower() : result; + return Platform::IsWindows() ? result.toLower() : result; }; return (check(path) == check(File::DefaultDownloadPath())); } @@ -380,7 +380,7 @@ void PanelController::saveSettings() const { const auto result = value.endsWith('/') ? value.mid(0, value.size() - 1) : value; - return (cPlatform() == dbipWindows) ? result.toLower() : result; + return Platform::IsWindows() ? result.toLower() : result; }; auto settings = *_settings; if (check(settings.path) == check(File::DefaultDownloadPath())) { diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 193ae55141..6850026158 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/clip/media_clip_reader.h" #include "window/window_controller.h" #include "history/history_item_components.h" +#include "platform/platform_info.h" #include "data/data_peer.h" #include "data/data_user.h" #include "observer_peer.h" @@ -436,7 +437,7 @@ struct Data { Notify::ScreenCorner NotificationsCorner = Notify::ScreenCorner::BottomRight; bool NotificationsDemoIsShown = false; - bool TryIPv6 = (cPlatform() == dbipWindows) ? false : true; + bool TryIPv6 = !Platform::IsWindows(); std::vector ProxiesList; ProxyData SelectedProxy; ProxyData::Settings ProxySettings = ProxyData::Settings::System; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 388c47ea64..48d78ea35a 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_cursor_state.h" #include "chat_helpers/message_field.h" #include "boxes/sticker_set_box.h" +#include "platform/platform_info.h" #include "mainwindow.h" #include "mainwidget.h" #include "core/application.h" @@ -1023,7 +1024,7 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } } if (!document->filepath(DocumentData::FilePathResolve::Checked).isEmpty()) { - _menu->addAction(lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_context_show_in_finder : lng_context_show_in_folder), [=] { + _menu->addAction(lang(Platform::IsMac() ? lng_context_show_in_finder : lng_context_show_in_folder), [=] { showContextInFolder(document); }); } diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 7edb524222..eceea3c82c 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -40,6 +40,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "auth_session.h" #include "core/application.h" #include "apiwrap.h" +#include "platform/platform_info.h" #include "lang/lang_keys.h" #include "data/data_session.h" #include "data/data_media_types.h" @@ -1558,7 +1559,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { }); } if (!document->filepath(DocumentData::FilePathResolve::Checked).isEmpty()) { - _menu->addAction(lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_context_show_in_finder : lng_context_show_in_folder), [=] { + _menu->addAction(lang(Platform::IsMac() ? lng_context_show_in_finder : lng_context_show_in_folder), [=] { showContextInFolder(document); }); } diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 16fc759d49..db9efbde5f 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_groups.h" #include "data/data_channel.h" #include "core/file_utilities.h" +#include "platform/platform_info.h" #include "window/window_peer_menu.h" #include "lang/lang_keys.h" #include "core/application.h" @@ -181,7 +182,7 @@ void AddDocumentActions( if (!document->filepath( DocumentData::FilePathResolve::Checked).isEmpty()) { menu->addAction( - lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) + lang(Platform::IsMac() ? lng_context_show_in_finder : lng_context_show_in_folder), [=] { ShowInFolder(document); }); diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index bd6dff00d2..aa125dd758 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/main_window.h" #include "styles/style_overview.h" #include "styles/style_info.h" +#include "platform/platform_info.h" #include "media/player/media_player_instance.h" #include "boxes/peer_list_controllers.h" #include "boxes/confirm_box.h" @@ -1267,7 +1268,7 @@ void ListWidget::showContextMenu( File::ShowInFolder(filepath); }); _contextMenu->addAction( - lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) + lang(Platform::IsMac() ? lng_context_show_in_finder : lng_context_show_in_folder), std::move(handler)); diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index fdbe7c4aba..a00872ae07 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -16,7 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/click_handler_types.h" #include "boxes/confirm_box.h" #include "base/qthelp_url.h" -#include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "core/application.h" namespace Intro { @@ -35,7 +35,7 @@ I'm trying to use my mobile phone number: ") + phone + qsl("\n\ But Telegram says it's banned. Please help.\n\ \n\ App version: ") + version + qsl("\n\ -OS version: ") + cPlatformString() + qsl("\n\ +OS version: ") + Platform::SystemVersionPretty() + qsl("\n\ Locale: ") + Platform::SystemLanguage(); const auto url = "mailto:?to=" diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index 0f83523970..4cb8d9fc4e 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_slide_animation.h" #include "window/window_connecting_widget.h" #include "window/window_lock_widgets.h" +#include "platform/platform_info.h" #include "data/data_user.h" #include "window/themes/window_theme.h" #include "lang/lang_cloud_manager.h" diff --git a/Telegram/SourceFiles/lang/lang_instance.cpp b/Telegram/SourceFiles/lang/lang_instance.cpp index 7824ac0b5e..6c5e67b45f 100644 --- a/Telegram/SourceFiles/lang/lang_instance.cpp +++ b/Telegram/SourceFiles/lang/lang_instance.cpp @@ -10,7 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "storage/serialize_common.h" #include "storage/localstorage.h" -#include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "boxes/confirm_box.h" #include "lang/lang_file_parser.h" #include "base/qthelp_regex.h" diff --git a/Telegram/SourceFiles/lang/lang_translator.cpp b/Telegram/SourceFiles/lang/lang_translator.cpp index 7d85373f80..f15468957c 100644 --- a/Telegram/SourceFiles/lang/lang_translator.cpp +++ b/Telegram/SourceFiles/lang/lang_translator.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_translator.h" #include "lang/lang_keys.h" +#include "platform/platform_info.h" namespace Lang { @@ -23,8 +24,8 @@ QString Translator::translate(const char *context, const char *sourceText, const return QString(); } if (qstr("QWidgetTextControl") == context || qstr("QLineEdit") == context) { - if (qstr("&Undo") == sourceText) return lang((cPlatform() == dbipWindows) ? lng_wnd_menu_undo : ((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_mac_menu_undo : lng_linux_menu_undo)); - if (qstr("&Redo") == sourceText) return lang((cPlatform() == dbipWindows) ? lng_wnd_menu_redo : ((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_mac_menu_redo : lng_linux_menu_redo)); + if (qstr("&Undo") == sourceText) return lang(Platform::IsWindows() ? lng_wnd_menu_undo : (Platform::IsMac() ? lng_mac_menu_undo : lng_linux_menu_undo)); + if (qstr("&Redo") == sourceText) return lang(Platform::IsWindows() ? lng_wnd_menu_redo : (Platform::IsMac() ? lng_mac_menu_redo : lng_linux_menu_redo)); if (qstr("Cu&t") == sourceText) return lang(lng_mac_menu_cut); if (qstr("&Copy") == sourceText) return lang(lng_mac_menu_copy); if (qstr("&Paste") == sourceText) return lang(lng_mac_menu_paste); diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 6098d3e7c1..45d140cd23 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "settings/settings_intro.h" #include "platform/platform_notifications_manager.h" +#include "platform/platform_info.h" #include "window/layer_widget.h" #include "window/notifications_manager.h" #include "window/themes/window_theme.h" @@ -124,12 +125,11 @@ void MainWindow::firstShow() { trayIconMenu = new QMenu(this); #endif // else for Q_OS_WIN - auto isLinux = (cPlatform() == dbipLinux32 || cPlatform() == dbipLinux64); auto notificationActionText = lang(Global::DesktopNotify() ? lng_disable_notifications_from_tray : lng_enable_notifications_from_tray); - if (isLinux) { + if (Platform::IsLinux()) { trayIconMenu->addAction(lang(lng_open_from_tray), this, SLOT(showFromTray())); trayIconMenu->addAction(lang(lng_minimize_to_tray), this, SLOT(minimizeToTray())); trayIconMenu->addAction(notificationActionText, this, SLOT(toggleDisplayNotifyFromTray())); @@ -541,12 +541,11 @@ bool MainWindow::eventFilter(QObject *object, QEvent *e) { } void MainWindow::updateTrayMenu(bool force) { - if (!trayIconMenu || (cPlatform() == dbipWindows && !force)) return; + if (!trayIconMenu || (Platform::IsWindows() && !force)) return; auto iconMenu = trayIconMenu; auto actions = iconMenu->actions(); - auto isLinux = (cPlatform() == dbipLinux32 || cPlatform() == dbipLinux64); - if (isLinux) { + if (Platform::IsLinux()) { auto minimizeAction = actions.at(1); minimizeAction->setDisabled(!isVisible()); } else { @@ -560,11 +559,11 @@ void MainWindow::updateTrayMenu(bool force) { // On macOS just remove trayIcon menu if the window is not active. // So we will activate the window on click instead of showing the menu. - if (!active && (cPlatform() == dbipMac || cPlatform() == dbipMacOld)) { + if (!active && Platform::IsMac()) { iconMenu = nullptr; } } - auto notificationAction = actions.at(isLinux ? 2 : 1); + auto notificationAction = actions.at(Platform::IsLinux() ? 2 : 1); auto notificationActionText = lang(Global::DesktopNotify() ? lng_disable_notifications_from_tray : lng_enable_notifications_from_tray); @@ -678,8 +677,7 @@ void MainWindow::showFromTray(QSystemTrayIcon::ActivationReason reason) { void MainWindow::handleTrayIconActication( QSystemTrayIcon::ActivationReason reason) { updateIsActive(0); - if ((cPlatform() == dbipMac || cPlatform() == dbipMacOld) - && isActive()) { + if (Platform::IsMac() && isActive()) { return; } if (reason == QSystemTrayIcon::Context) { diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index c599d3d724..ff47b971d3 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "core/file_utilities.h" #include "core/mime_type.h" +#include "platform/platform_info.h" #include "ui/widgets/popup_menu.h" #include "ui/widgets/buttons.h" #include "ui/image/image.h" @@ -289,11 +290,11 @@ OverlayWidget::OverlayWidget() hide(); createWinId(); - if (cPlatform() == dbipLinux32 || cPlatform() == dbipLinux64) { + if (Platform::IsLinux()) { windowHandle()->setTransientParent(App::wnd()->windowHandle()); setWindowModality(Qt::WindowModal); } - if (cPlatform() != dbipMac && cPlatform() != dbipMacOld) { + if (!Platform::IsMac()) { setWindowState(Qt::WindowFullScreen); } @@ -646,7 +647,7 @@ void OverlayWidget::updateActions() { _actions.push_back({ lang(lng_context_to_msg), SLOT(onToMessage()) }); } if (_doc && !_doc->filepath(DocumentData::FilePathResolve::Checked).isEmpty()) { - _actions.push_back({ lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_context_show_in_finder : lng_context_show_in_folder), SLOT(onShowInFolder()) }); + _actions.push_back({ lang(Platform::IsMac() ? lng_context_show_in_finder : lng_context_show_in_folder), SLOT(onShowInFolder()) }); } if ((_doc && documentContentShown()) || (_photo && _photo->loaded())) { _actions.push_back({ lang(lng_mediaview_copy), SLOT(onCopy()) }); diff --git a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp index 5405ce5b8e..1bf733cd87 100644 --- a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp @@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "passport/passport_panel_controller.h" #include "lang/lang_keys.h" -#include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "ui/widgets/input_fields.h" #include "ui/widgets/labels.h" #include "ui/widgets/buttons.h" diff --git a/Telegram/SourceFiles/platform/linux/info_linux.cpp b/Telegram/SourceFiles/platform/linux/info_linux.cpp new file mode 100644 index 0000000000..9a8092c999 --- /dev/null +++ b/Telegram/SourceFiles/platform/linux/info_linux.cpp @@ -0,0 +1,35 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "platform/linux/info_linux.h" + +namespace Platform { + +QString DeviceModelPretty() { +#ifdef Q_OS_LINUX64 + return "PC 64bit"; +#else // Q_OS_LINUX64 + return "PC 32bit"; +#endif // Q_OS_LINUX64 +} + +QString SystemVersionPretty() { + 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]; +} + +QString SystemCountry() { + return QString(); +} + +QString SystemLanguage() { + return QString(); +} + +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/info_linux.h b/Telegram/SourceFiles/platform/linux/info_linux.h new file mode 100644 index 0000000000..f4bbc51a05 --- /dev/null +++ b/Telegram/SourceFiles/platform/linux/info_linux.h @@ -0,0 +1,53 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +namespace Platform { + +inline constexpr bool IsLinux() { + return true; +} + +inline constexpr bool IsLinux32Bit() { +#ifdef Q_OS_LINUX32 + return true; +#else // Q_OS_LINUX32 + return false; +#endif // Q_OS_LINUX32 +} + +inline constexpr bool IsLinux64Bit() { +#ifdef Q_OS_LINUX64 + return true; +#else // Q_OS_LINUX64 + return false; +#endif // Q_OS_LINUX64 +} + +inline constexpr bool IsWindows() { return false; } +inline constexpr bool IsWindowsStoreBuild() { return false; } +inline bool IsWindowsXPOrGreater() { return false; } +inline bool IsWindowsVistaOrGreater() { return false; } +inline bool IsWindows7OrGreater() { return false; } +inline bool IsWindows8OrGreater() { return false; } +inline bool IsWindows8Point1OrGreater() { return false; } +inline bool IsWindows10OrGreater() { return false; } +inline constexpr bool IsMac() { return false; } +inline constexpr bool IsMacOldBuild() { return false; } +inline constexpr bool IsMacStoreBuild() { return false; } +inline bool IsMac10_6OrGreater() { return false; } +inline bool IsMac10_7OrGreater() { return false; } +inline bool IsMac10_8OrGreater() { return false; } +inline bool IsMac10_9OrGreater() { return false; } +inline bool IsMac10_10OrGreater() { return false; } +inline bool IsMac10_11OrGreater() { return false; } +inline bool IsMac10_12OrGreater() { return false; } +inline bool IsMac10_13OrGreater() { return false; } +inline bool IsMac10_14OrGreater() { return false; } + +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp index fae2332cae..2722ffbff4 100644 --- a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "platform/linux/launcher_linux.h" +#include "platform/platform_info.h" #include "core/crash_reports.h" #include "core/update_checker.h" @@ -39,25 +40,10 @@ 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()) { +: Core::Launcher(argc, argv, DeviceModelPretty(), SystemVersionPretty()) { } bool Launcher::launchUpdater(UpdaterLaunch action) { diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 31f32cc664..5aec256997 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -283,14 +283,6 @@ bool TranslucentWindowsSupported(QPoint globalPosition) { return false; } -QString SystemCountry() { - return QString(); -} - -QString SystemLanguage() { - return QString(); -} - void RegisterCustomScheme() { #ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME auto home = getHomeDir(); diff --git a/Telegram/SourceFiles/platform/mac/info_mac.cpp b/Telegram/SourceFiles/platform/mac/info_mac.cpp new file mode 100644 index 0000000000..7899398929 --- /dev/null +++ b/Telegram/SourceFiles/platform/mac/info_mac.cpp @@ -0,0 +1,9 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "platform/mac/info_mac.h" + diff --git a/Telegram/SourceFiles/platform/mac/info_mac.h b/Telegram/SourceFiles/platform/mac/info_mac.h new file mode 100644 index 0000000000..5f92a21dd9 --- /dev/null +++ b/Telegram/SourceFiles/platform/mac/info_mac.h @@ -0,0 +1,44 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +namespace Platform { + +inline constexpr bool IsMac() { + return true; +} + +inline constexpr bool IsMacOldBuild() { +#ifdef OS_MAC_OLD + return true; +#else // OS_MAC_OLD + return false; +#endif // OS_MAC_OLD +} + +inline constexpr bool IsMacStoreBuild() { +#ifdef OS_MAC_STORE + return true; +#else // OS_MAC_STORE + return false; +#endif // OS_MAC_STORE +} + +inline constexpr bool IsWindows() { return false; } +inline constexpr bool IsWindowsStoreBuild() { return false; } +inline bool IsWindowsXPOrGreater() { return false; } +inline bool IsWindowsVistaOrGreater() { return false; } +inline bool IsWindows7OrGreater() { return false; } +inline bool IsWindows8OrGreater() { return false; } +inline bool IsWindows8Point1OrGreater() { return false; } +inline bool IsWindows10OrGreater() { return false; } +inline constexpr bool IsLinux() { return false; } +inline constexpr bool IsLinux32Bit() { return false; } +inline constexpr bool IsLinux64Bit() { return false; } + +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/mac/info_mac.mm b/Telegram/SourceFiles/platform/mac/info_mac.mm new file mode 100644 index 0000000000..4576c050d0 --- /dev/null +++ b/Telegram/SourceFiles/platform/mac/info_mac.mm @@ -0,0 +1,153 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "platform/mac/info_mac.h" + +#include "platform/mac/mac_utilities.h" + +#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; +} + +int MinorVersion() { + static const int version = QSysInfo::macVersion(); + constexpr int kShift = 2; + if (version == QSysInfo::MV_Unknown +#ifndef OS_MAC_OLD + || version == QSysInfo::MV_None +#endif // OS_MAC_OLD + || version < kShift + 6) { + return 0; + } + return version - kShift; +} + +template +bool IsMacThatOrGreater() { + static const auto result = (MinorVersion() >= Minor); + return result; +} + +} // namespace + +QString DeviceModelPretty() { + 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 SystemVersionPretty() { + const auto version = MinorVersion(); + if (!version) { + return "OS X"; + } else if (version < 12) { + return QString("OS X 10.%1").arg(version); + } + return QString("macOS 10.%1").arg(version); +} + +QString SystemCountry() { + NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale. + NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; + return countryCode ? NS2QString(countryCode) : QString(); +} + +QString SystemLanguage() { + if (auto currentLocale = [NSLocale currentLocale]) { // get the current locale. + if (NSString *collator = [currentLocale objectForKey:NSLocaleCollatorIdentifier]) { + return NS2QString(collator); + } + if (NSString *identifier = [currentLocale objectForKey:NSLocaleIdentifier]) { + return NS2QString(identifier); + } + if (NSString *language = [currentLocale objectForKey:NSLocaleLanguageCode]) { + return NS2QString(language); + } + } + return QString(); +} + +bool IsMac10_6OrGreater() { + return IsMacThatOrGreater<6>(); +} + +bool IsMac10_7OrGreater() { + return IsMacThatOrGreater<7>(); +} + +bool IsMac10_8OrGreater() { + return IsMacThatOrGreater<8>(); +} + +bool IsMac10_9OrGreater() { + return IsMacThatOrGreater<9>(); +} + +bool IsMac10_10OrGreater() { + return IsMacThatOrGreater<10>(); +} + +bool IsMac10_11OrGreater() { + return IsMacThatOrGreater<11>(); +} + +bool IsMac10_12OrGreater() { + return IsMacThatOrGreater<12>(); +} + +bool IsMac10_13OrGreater() { + return IsMacThatOrGreater<13>(); +} + +bool IsMac10_14OrGreater() { + return IsMacThatOrGreater<14>(); +} + +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/mac/launcher_mac.mm b/Telegram/SourceFiles/platform/mac/launcher_mac.mm index bb3d94470a..23d4dadca4 100644 --- a/Telegram/SourceFiles/platform/mac/launcher_mac.mm +++ b/Telegram/SourceFiles/platform/mac/launcher_mac.mm @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/crash_reports.h" #include "core/update_checker.h" #include "platform/mac/mac_utilities.h" +#include "platform/platform_info.h" #include "platform/platform_specific.h" #include @@ -17,74 +18,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #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_Unknown -#ifndef OS_MAC_OLD - || version == QSysInfo::MV_None -#endif // OS_MAC_OLD - || 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()) { +: Core::Launcher(argc, argv, DeviceModelPretty(), SystemVersionPretty()) { } void Launcher::initHook() { diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 6ea86253d6..28a970918a 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/notifications_manager_default.h" #include "window/themes/window_theme.h" #include "platform/platform_notifications_manager.h" +#include "platform/platform_info.h" #include "boxes/peer_list_controllers.h" #include "boxes/about_box.h" #include "lang/lang_keys.h" @@ -400,14 +401,7 @@ MainWindow::MainWindow() } void MainWindow::initTouchBar() { - const int version = QSysInfo::macVersion(); - constexpr int kShift = 2; - if (version == QSysInfo::MV_Unknown -#ifndef OS_MAC_OLD - || version == QSysInfo::MV_None -#endif // OS_MAC_OLD - // Allow touch bar only starting with 10.13. - || version < kShift + 13) { + if (!IsMac10_13OrGreater()) { return; } diff --git a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm index cbf3e91ec7..00a393b41a 100644 --- a/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm +++ b/Telegram/SourceFiles/platform/mac/notifications_manager_mac.mm @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/mac/notifications_manager_mac.h" #include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "platform/mac/mac_utilities.h" #include "history/history.h" #include "mainwindow.h" @@ -141,7 +142,7 @@ bool SkipToast() { } bool Supported() { - return (cPlatform() != dbipMacOld); + return Platform::IsMac10_8OrGreater(); } std::unique_ptr Create(Window::Notifications::System *system) { diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.mm b/Telegram/SourceFiles/platform/mac/specific_mac.mm index 7d67206e02..dab1a74d02 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac.mm @@ -153,27 +153,6 @@ void StartTranslucentPaint(QPainter &p, QPaintEvent *e) { #endif // OS_MAC_OLD } -QString SystemCountry() { - NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale. - NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; - return countryCode ? NS2QString(countryCode) : QString(); -} - -QString SystemLanguage() { - if (auto currentLocale = [NSLocale currentLocale]) { // get the current locale. - if (NSString *collator = [currentLocale objectForKey:NSLocaleCollatorIdentifier]) { - return NS2QString(collator); - } - if (NSString *identifier = [currentLocale objectForKey:NSLocaleIdentifier]) { - return NS2QString(identifier); - } - if (NSString *language = [currentLocale objectForKey:NSLocaleLanguageCode]) { - return NS2QString(language); - } - } - return QString(); -} - QString CurrentExecutablePath(int argc, char *argv[]) { return NS2QString([[NSBundle mainBundle] bundlePath]); } diff --git a/Telegram/SourceFiles/platform/mac/specific_mac_p.mm b/Telegram/SourceFiles/platform/mac/specific_mac_p.mm index 2e8b5ed4b7..1dfdf35c43 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac_p.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac_p.mm @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/player/media_player_instance.h" #include "platform/mac/mac_touchbar.h" #include "platform/mac/mac_utilities.h" +#include "platform/platform_info.h" #include "lang/lang_keys.h" #include "base/timer.h" #include "styles/style_window.h" @@ -125,15 +126,11 @@ ApplicationDelegate *_sharedDelegate = nil; }); #ifndef OS_MAC_STORE if ([SPMediaKeyTap usesGlobalMediaKeyTap]) { -#ifndef OS_MAC_OLD - if (QSysInfo::macVersion() < Q_MV_OSX(10, 14)) { -#else // OS_MAC_OLD - if (true) { -#endif // OS_MAC_OLD + if (!Platform::IsMac10_14OrGreater()) { _keyTap = [[SPMediaKeyTap alloc] initWithDelegate:self]; } else { // In macOS Mojave it requires accessibility features. - LOG(("Media key monitoring disabled in Mojave.")); + LOG(("Media key monitoring disabled starting with Mojave.")); } } else { LOG(("Media key monitoring disabled")); diff --git a/Telegram/SourceFiles/platform/platform_info.h b/Telegram/SourceFiles/platform/platform_info.h new file mode 100644 index 0000000000..d35991b6ab --- /dev/null +++ b/Telegram/SourceFiles/platform/platform_info.h @@ -0,0 +1,51 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +namespace Platform { + +[[nodiscard]] QString DeviceModelPretty(); +[[nodiscard]] QString SystemVersionPretty(); +[[nodiscard]] QString SystemCountry(); +[[nodiscard]] QString SystemLanguage(); + +[[nodiscard]] constexpr bool IsWindows(); +[[nodiscard]] constexpr bool IsWindowsStoreBuild(); +[[nodiscard]] bool IsWindowsXPOrGreater(); +[[nodiscard]] bool IsWindowsVistaOrGreater(); +[[nodiscard]] bool IsWindows7OrGreater(); +[[nodiscard]] bool IsWindows8OrGreater(); +[[nodiscard]] bool IsWindows8Point1OrGreater(); +[[nodiscard]] bool IsWindows10OrGreater(); + +[[nodiscard]] constexpr bool IsMac(); +[[nodiscard]] constexpr bool IsMacOldBuild(); +[[nodiscard]] constexpr bool IsMacStoreBuild(); +[[nodiscard]] bool IsMac10_6OrGreater(); +[[nodiscard]] bool IsMac10_7OrGreater(); +[[nodiscard]] bool IsMac10_8OrGreater(); +[[nodiscard]] bool IsMac10_9OrGreater(); +[[nodiscard]] bool IsMac10_10OrGreater(); +[[nodiscard]] bool IsMac10_11OrGreater(); +[[nodiscard]] bool IsMac10_12OrGreater(); +[[nodiscard]] bool IsMac10_13OrGreater(); +[[nodiscard]] bool IsMac10_14OrGreater(); + +[[nodiscard]] constexpr bool IsLinux(); +[[nodiscard]] constexpr bool IsLinux32Bit(); +[[nodiscard]] constexpr bool IsLinux64Bit(); + +} // namespace Platform + +#ifdef Q_OS_MAC +#include "platform/mac/info_mac.h" +#elif defined Q_OS_LINUX // Q_OS_MAC +#include "platform/linux/info_linux.h" +#elif defined Q_OS_WIN // Q_OS_MAC || Q_OS_LINUX +#include "platform/win/info_win.h" +#endif // Q_OS_MAC || Q_OS_LINUX || Q_OS_WIN diff --git a/Telegram/SourceFiles/platform/platform_specific.h b/Telegram/SourceFiles/platform/platform_specific.h index 919065a02d..5700cc9746 100644 --- a/Telegram/SourceFiles/platform/platform_specific.h +++ b/Telegram/SourceFiles/platform/platform_specific.h @@ -40,9 +40,6 @@ void RequestPermission(PermissionType type, Fn resultCal void OpenSystemSettingsForPermission(PermissionType type); bool OpenSystemSettings(SystemSettingsType type); -[[nodiscard]] QString SystemLanguage(); -[[nodiscard]] QString SystemCountry(); - [[nodiscard]] std::optional LastUserInputTime(); [[nodiscard]] inline bool LastUserInputTimeSupported() { return LastUserInputTime().has_value(); diff --git a/Telegram/SourceFiles/platform/win/info_win.cpp b/Telegram/SourceFiles/platform/win/info_win.cpp new file mode 100644 index 0000000000..3c7ebd0ae0 --- /dev/null +++ b/Telegram/SourceFiles/platform/win/info_win.cpp @@ -0,0 +1,244 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "platform/win/info_win.h" + +#include "platform/platform_info.h" +#include "platform/win/wrapper_windows_h.h" + +#include + +namespace Platform { +namespace { + +QString GetLangCodeById(unsigned int lngId) { + const auto primary = (lngId & 0xFFU); + switch (primary) { + case 0x36: return qsl("af"); + case 0x1C: return qsl("sq"); + case 0x5E: return qsl("am"); + case 0x01: return qsl("ar"); + case 0x2B: return qsl("hy"); + case 0x4D: return qsl("as"); + case 0x2C: return qsl("az"); + case 0x45: return qsl("bn"); + case 0x6D: return qsl("ba"); + case 0x2D: return qsl("eu"); + case 0x23: return qsl("be"); + case 0x1A: + if (lngId == LANG_CROATIAN) { + return qsl("hr"); + } else if (lngId == LANG_BOSNIAN_NEUTRAL || lngId == LANG_BOSNIAN) { + return qsl("bs"); + } + return qsl("sr"); + break; + case 0x7E: return qsl("br"); + case 0x02: return qsl("bg"); + case 0x92: return qsl("ku"); + case 0x03: return qsl("ca"); + case 0x04: return qsl("zh"); + case 0x83: return qsl("co"); + case 0x05: return qsl("cs"); + case 0x06: return qsl("da"); + case 0x65: return qsl("dv"); + case 0x13: return qsl("nl"); + case 0x09: return qsl("en"); + case 0x25: return qsl("et"); + case 0x38: return qsl("fo"); + case 0x0B: return qsl("fi"); + case 0x0c: return qsl("fr"); + case 0x62: return qsl("fy"); + case 0x56: return qsl("gl"); + case 0x37: return qsl("ka"); + case 0x07: return qsl("de"); + case 0x08: return qsl("el"); + case 0x6F: return qsl("kl"); + case 0x47: return qsl("gu"); + case 0x68: return qsl("ha"); + case 0x0D: return qsl("he"); + case 0x39: return qsl("hi"); + case 0x0E: return qsl("hu"); + case 0x0F: return qsl("is"); + case 0x70: return qsl("ig"); + case 0x21: return qsl("id"); + case 0x5D: return qsl("iu"); + case 0x3C: return qsl("ga"); + case 0x34: return qsl("xh"); + case 0x35: return qsl("zu"); + case 0x10: return qsl("it"); + case 0x11: return qsl("ja"); + case 0x4B: return qsl("kn"); + case 0x3F: return qsl("kk"); + case 0x53: return qsl("kh"); + case 0x87: return qsl("rw"); + case 0x12: return qsl("ko"); + case 0x40: return qsl("ky"); + case 0x54: return qsl("lo"); + case 0x26: return qsl("lv"); + case 0x27: return qsl("lt"); + case 0x6E: return qsl("lb"); + case 0x2F: return qsl("mk"); + case 0x3E: return qsl("ms"); + case 0x4C: return qsl("ml"); + case 0x3A: return qsl("mt"); + case 0x81: return qsl("mi"); + case 0x4E: return qsl("mr"); + case 0x50: return qsl("mn"); + case 0x61: return qsl("ne"); + case 0x14: return qsl("no"); + case 0x82: return qsl("oc"); + case 0x48: return qsl("or"); + case 0x63: return qsl("ps"); + case 0x29: return qsl("fa"); + case 0x15: return qsl("pl"); + case 0x16: return qsl("pt"); + case 0x67: return qsl("ff"); + case 0x46: return qsl("pa"); + case 0x18: return qsl("ro"); + case 0x17: return qsl("rm"); + case 0x19: return qsl("ru"); + case 0x3B: return qsl("se"); + case 0x4F: return qsl("sa"); + case 0x32: return qsl("tn"); + case 0x59: return qsl("sd"); + case 0x5B: return qsl("si"); + case 0x1B: return qsl("sk"); + case 0x24: return qsl("sl"); + case 0x0A: return qsl("es"); + case 0x41: return qsl("sw"); + case 0x1D: return qsl("sv"); + case 0x28: return qsl("tg"); + case 0x49: return qsl("ta"); + case 0x44: return qsl("tt"); + case 0x4A: return qsl("te"); + case 0x1E: return qsl("th"); + case 0x51: return qsl("bo"); + case 0x73: return qsl("ti"); + case 0x1F: return qsl("tr"); + case 0x42: return qsl("tk"); + case 0x22: return qsl("uk"); + case 0x20: return qsl("ur"); + case 0x80: return qsl("ug"); + case 0x43: return qsl("uz"); + case 0x2A: return qsl("vi"); + case 0x52: return qsl("cy"); + case 0x88: return qsl("wo"); + case 0x78: return qsl("ii"); + case 0x6A: return qsl("yo"); + } + return QString(); +} + +} // namespace + +QString DeviceModelPretty() { + return "PC"; +} + +QString SystemVersionPretty() { + if (IsWindows10OrGreater()) { + return "Windows 10"; + } else if (IsWindows8Point1OrGreater()) { + return "Windows 8.1"; + } else if (IsWindows8OrGreater()) { + return "Windows 8"; + } else if (IsWindows7OrGreater()) { + return "Windows 7"; + } else if (IsWindowsVistaOrGreater()) { + return "Windows Vista"; + } else if (IsWindowsXPOrGreater()) { + return "Windows XP"; + } else { + return QSysInfo::prettyProductName(); + } +} + +QString SystemCountry() { + int chCount = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, 0, 0); + if (chCount && chCount < 128) { + WCHAR wstrCountry[128]; + int len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, wstrCountry, chCount); + if (len) { + return QString::fromStdWString(std::wstring(wstrCountry)); + } + } + return QString(); +} + +QString SystemLanguage() { + constexpr auto kMaxLanguageLength = 128; + + auto uiLanguageId = GetUserDefaultUILanguage(); + auto uiLanguageLength = GetLocaleInfo(uiLanguageId, LOCALE_SNAME, nullptr, 0); + if (uiLanguageLength > 0 && uiLanguageLength < kMaxLanguageLength) { + WCHAR uiLanguageWideString[kMaxLanguageLength] = { 0 }; + uiLanguageLength = GetLocaleInfo(uiLanguageId, LOCALE_SNAME, uiLanguageWideString, uiLanguageLength); + if (uiLanguageLength <= 0) { + return QString(); + } + return QString::fromWCharArray(uiLanguageWideString); + } + auto uiLanguageCodeLength = GetLocaleInfo(uiLanguageId, LOCALE_ILANGUAGE, nullptr, 0); + if (uiLanguageCodeLength > 0 && uiLanguageCodeLength < kMaxLanguageLength) { + WCHAR uiLanguageCodeWideString[kMaxLanguageLength] = { 0 }; + uiLanguageCodeLength = GetLocaleInfo(uiLanguageId, LOCALE_ILANGUAGE, uiLanguageCodeWideString, uiLanguageCodeLength); + if (uiLanguageCodeLength <= 0) { + return QString(); + } + + auto languageCode = 0U; + for (auto i = 0; i != uiLanguageCodeLength; ++i) { + auto ch = uiLanguageCodeWideString[i]; + if (!ch) { + break; + } + languageCode *= 0x10U; + if (ch >= WCHAR('0') && ch <= WCHAR('9')) { + languageCode += static_cast(int(ch) - int(WCHAR('0'))); + } else if (ch >= WCHAR('A') && ch <= WCHAR('F')) { + languageCode += static_cast(0x0A + int(ch) - int(WCHAR('A'))); + } else { + return QString(); + } + } + return GetLangCodeById(languageCode); + } + return QString(); +} + +bool IsWindowsXPOrGreater() { + static const auto result = ::IsWindowsXPOrGreater(); + return result; +} + +bool IsWindowsVistaOrGreater() { + static const auto result = ::IsWindowsVistaOrGreater(); + return result; +} + +bool IsWindows7OrGreater() { + static const auto result = ::IsWindows7OrGreater(); + return result; +} + +bool IsWindows8OrGreater() { + static const auto result = ::IsWindows8OrGreater(); + return result; +} + +bool IsWindows8Point1OrGreater() { + static const auto result = ::IsWindows8Point1OrGreater(); + return result; +} + +bool IsWindows10OrGreater() { + static const auto result = ::IsWindows10OrGreater(); + return result; +} + +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/win/info_win.h b/Telegram/SourceFiles/platform/win/info_win.h new file mode 100644 index 0000000000..8c2d974883 --- /dev/null +++ b/Telegram/SourceFiles/platform/win/info_win.h @@ -0,0 +1,40 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +namespace Platform { + +inline constexpr bool IsWindows() { + return true; +} + +inline constexpr bool IsWindowsStoreBuild() { +#ifdef OS_WIN_STORE + return true; +#else // OS_WIN_STORE + return false; +#endif // OS_WIN_STORE +} + +inline constexpr bool IsMac() { return false; } +inline constexpr bool IsMacOldBuild() { return false; } +inline constexpr bool IsMacStoreBuild() { return false; } +inline bool IsMac10_6OrGreater() { return false; } +inline bool IsMac10_7OrGreater() { return false; } +inline bool IsMac10_8OrGreater() { return false; } +inline bool IsMac10_9OrGreater() { return false; } +inline bool IsMac10_10OrGreater() { return false; } +inline bool IsMac10_11OrGreater() { return false; } +inline bool IsMac10_12OrGreater() { return false; } +inline bool IsMac10_13OrGreater() { return false; } +inline bool IsMac10_14OrGreater() { return false; } +inline constexpr bool IsLinux() { return false; } +inline constexpr bool IsLinux32Bit() { return false; } +inline constexpr bool IsLinux64Bit() { return false; } + +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/win/launcher_win.cpp b/Telegram/SourceFiles/platform/win/launcher_win.cpp index 0c460a7d55..5eda272fb1 100644 --- a/Telegram/SourceFiles/platform/win/launcher_win.cpp +++ b/Telegram/SourceFiles/platform/win/launcher_win.cpp @@ -9,41 +9,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/crash_reports.h" #include "core/update_checker.h" -#include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "platform/win/wrapper_windows_h.h" #include #include namespace Platform { -namespace { - -QString DeviceModel() { - return "PC"; -} - -QString SystemVersion() { - if (IsWindows10OrGreater()) { - return "Windows 10"; - } else if (IsWindows8Point1OrGreater()) { - return "Windows 8.1"; - } else if (IsWindows8OrGreater()) { - return "Windows 8"; - } else if (IsWindows7OrGreater()) { - return "Windows 7"; - } else if (IsWindowsVistaOrGreater()) { - return "Windows Vista"; - } else if (IsWindowsXPOrGreater()) { - return "Windows XP"; - } else { - return QSysInfo::prettyProductName(); - } -} - -} // namespace Launcher::Launcher(int argc, char *argv[]) -: Core::Launcher(argc, argv, DeviceModel(), SystemVersion()) { +: Core::Launcher(argc, argv, DeviceModelPretty(), SystemVersionPretty()) { } std::optional Launcher::readArgumentsHook( diff --git a/Telegram/SourceFiles/platform/win/specific_win.cpp b/Telegram/SourceFiles/platform/win/specific_win.cpp index ea8071405a..6cc5d90ab2 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.cpp +++ b/Telegram/SourceFiles/platform/win/specific_win.cpp @@ -289,18 +289,6 @@ void finish() { EventFilter::destroy(); } -QString SystemCountry() { - int chCount = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, 0, 0); - if (chCount && chCount < 128) { - WCHAR wstrCountry[128]; - int len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, wstrCountry, chCount); - if (len) { - return QString::fromStdWString(std::wstring(wstrCountry)); - } - } - return QString(); -} - bool IsApplicationActive() { return QApplication::activeWindow() != nullptr; } @@ -335,170 +323,6 @@ std::optional LastUserInputTime() { : std::nullopt; } -namespace { - -QString GetLangCodeById(unsigned lngId) { - auto primary = (lngId & 0xFFU); - switch (primary) { - case 0x36: return qsl("af"); - case 0x1C: return qsl("sq"); - case 0x5E: return qsl("am"); - case 0x01: return qsl("ar"); - case 0x2B: return qsl("hy"); - case 0x4D: return qsl("as"); - case 0x2C: return qsl("az"); - case 0x45: return qsl("bn"); - case 0x6D: return qsl("ba"); - case 0x2D: return qsl("eu"); - case 0x23: return qsl("be"); - case 0x1A: - if (lngId == LANG_CROATIAN) { - return qsl("hr"); - } else if (lngId == LANG_BOSNIAN_NEUTRAL || lngId == LANG_BOSNIAN) { - return qsl("bs"); - } - return qsl("sr"); - break; - case 0x7E: return qsl("br"); - case 0x02: return qsl("bg"); - case 0x92: return qsl("ku"); - case 0x03: return qsl("ca"); - case 0x04: return qsl("zh"); - case 0x83: return qsl("co"); - case 0x05: return qsl("cs"); - case 0x06: return qsl("da"); - case 0x65: return qsl("dv"); - case 0x13: return qsl("nl"); - case 0x09: return qsl("en"); - case 0x25: return qsl("et"); - case 0x38: return qsl("fo"); - case 0x0B: return qsl("fi"); - case 0x0c: return qsl("fr"); - case 0x62: return qsl("fy"); - case 0x56: return qsl("gl"); - case 0x37: return qsl("ka"); - case 0x07: return qsl("de"); - case 0x08: return qsl("el"); - case 0x6F: return qsl("kl"); - case 0x47: return qsl("gu"); - case 0x68: return qsl("ha"); - case 0x0D: return qsl("he"); - case 0x39: return qsl("hi"); - case 0x0E: return qsl("hu"); - case 0x0F: return qsl("is"); - case 0x70: return qsl("ig"); - case 0x21: return qsl("id"); - case 0x5D: return qsl("iu"); - case 0x3C: return qsl("ga"); - case 0x34: return qsl("xh"); - case 0x35: return qsl("zu"); - case 0x10: return qsl("it"); - case 0x11: return qsl("ja"); - case 0x4B: return qsl("kn"); - case 0x3F: return qsl("kk"); - case 0x53: return qsl("kh"); - case 0x87: return qsl("rw"); - case 0x12: return qsl("ko"); - case 0x40: return qsl("ky"); - case 0x54: return qsl("lo"); - case 0x26: return qsl("lv"); - case 0x27: return qsl("lt"); - case 0x6E: return qsl("lb"); - case 0x2F: return qsl("mk"); - case 0x3E: return qsl("ms"); - case 0x4C: return qsl("ml"); - case 0x3A: return qsl("mt"); - case 0x81: return qsl("mi"); - case 0x4E: return qsl("mr"); - case 0x50: return qsl("mn"); - case 0x61: return qsl("ne"); - case 0x14: return qsl("no"); - case 0x82: return qsl("oc"); - case 0x48: return qsl("or"); - case 0x63: return qsl("ps"); - case 0x29: return qsl("fa"); - case 0x15: return qsl("pl"); - case 0x16: return qsl("pt"); - case 0x67: return qsl("ff"); - case 0x46: return qsl("pa"); - case 0x18: return qsl("ro"); - case 0x17: return qsl("rm"); - case 0x19: return qsl("ru"); - case 0x3B: return qsl("se"); - case 0x4F: return qsl("sa"); - case 0x32: return qsl("tn"); - case 0x59: return qsl("sd"); - case 0x5B: return qsl("si"); - case 0x1B: return qsl("sk"); - case 0x24: return qsl("sl"); - case 0x0A: return qsl("es"); - case 0x41: return qsl("sw"); - case 0x1D: return qsl("sv"); - case 0x28: return qsl("tg"); - case 0x49: return qsl("ta"); - case 0x44: return qsl("tt"); - case 0x4A: return qsl("te"); - case 0x1E: return qsl("th"); - case 0x51: return qsl("bo"); - case 0x73: return qsl("ti"); - case 0x1F: return qsl("tr"); - case 0x42: return qsl("tk"); - case 0x22: return qsl("uk"); - case 0x20: return qsl("ur"); - case 0x80: return qsl("ug"); - case 0x43: return qsl("uz"); - case 0x2A: return qsl("vi"); - case 0x52: return qsl("cy"); - case 0x88: return qsl("wo"); - case 0x78: return qsl("ii"); - case 0x6A: return qsl("yo"); - } - return QString(); -} - -} // namespace - -QString SystemLanguage() { - constexpr auto kMaxLanguageLength = 128; - - auto uiLanguageId = GetUserDefaultUILanguage(); - auto uiLanguageLength = GetLocaleInfo(uiLanguageId, LOCALE_SNAME, nullptr, 0); - if (uiLanguageLength > 0 && uiLanguageLength < kMaxLanguageLength) { - WCHAR uiLanguageWideString[kMaxLanguageLength] = { 0 }; - uiLanguageLength = GetLocaleInfo(uiLanguageId, LOCALE_SNAME, uiLanguageWideString, uiLanguageLength); - if (uiLanguageLength <= 0) { - return QString(); - } - return QString::fromWCharArray(uiLanguageWideString); - } - auto uiLanguageCodeLength = GetLocaleInfo(uiLanguageId, LOCALE_ILANGUAGE, nullptr, 0); - if (uiLanguageCodeLength > 0 && uiLanguageCodeLength < kMaxLanguageLength) { - WCHAR uiLanguageCodeWideString[kMaxLanguageLength] = { 0 }; - uiLanguageCodeLength = GetLocaleInfo(uiLanguageId, LOCALE_ILANGUAGE, uiLanguageCodeWideString, uiLanguageCodeLength); - if (uiLanguageCodeLength <= 0) { - return QString(); - } - - auto languageCode = 0U; - for (auto i = 0; i != uiLanguageCodeLength; ++i) { - auto ch = uiLanguageCodeWideString[i]; - if (!ch) { - break; - } - languageCode *= 0x10U; - if (ch >= WCHAR('0') && ch <= WCHAR('9')) { - languageCode += static_cast(int(ch) - int(WCHAR('0'))); - } else if (ch >= WCHAR('A') && ch <= WCHAR('F')) { - languageCode += static_cast(0x0A + int(ch) - int(WCHAR('A'))); - } else { - return QString(); - } - } - return GetLangCodeById(languageCode); - } - return QString(); -} - } // namespace Platform namespace { diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index dbe104f70e..bd1ab24f06 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -67,23 +67,6 @@ crl::time gPasscodeLastTry = 0; float64 gRetinaFactor = 1.; int32 gIntRetinaFactor = 1; -#ifdef Q_OS_WIN -DBIPlatform gPlatform = dbipWindows; -#elif defined OS_MAC_OLD -DBIPlatform gPlatform = dbipMacOld; -#elif defined Q_OS_MAC -DBIPlatform gPlatform = dbipMac; -#elif defined Q_OS_LINUX64 -DBIPlatform gPlatform = dbipLinux64; -#elif defined Q_OS_LINUX32 -DBIPlatform gPlatform = dbipLinux32; -#else -#error Unknown platform -#endif -QString gPlatformString; -bool gIsElCapitan = false; -bool gIsSnowLeopard = false; - int gOtherOnline = 0; ReportSpamStatuses gReportSpamStatuses; diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index b95dcfcae2..3f59dd5149 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -157,11 +157,6 @@ DeclareSetting(QString, StartUrl); DeclareSetting(float64, RetinaFactor); DeclareSetting(int32, IntRetinaFactor); -DeclareReadSetting(DBIPlatform, Platform); -DeclareReadSetting(QString, PlatformString); -DeclareReadSetting(bool, IsElCapitan); -DeclareReadSetting(bool, IsSnowLeopard); - DeclareSetting(int, OtherOnline); typedef QMap ReportSpamStatuses; diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp index 4eb350c448..a0afa22599 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_button.h" #include "info/profile/info_profile_values.h" #include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "lang/lang_keys.h" #include "core/update_checker.h" #include "core/application.h" @@ -239,7 +240,7 @@ void SetupUpdate(not_null container) { } bool HasTray() { - return cSupportTray() || (cPlatform() == dbipWindows); + return cSupportTray() || Platform::IsWindows(); } void SetupTrayContent(not_null container) { @@ -277,7 +278,7 @@ void SetupTrayContent(not_null container) { return (workMode == dbiwmWindowOnly) || (workMode == dbiwmWindowAndTray); }; - const auto taskbar = (cPlatform() == dbipWindows) + const auto taskbar = Platform::IsWindows() ? addCheckbox( lng_settings_workmode_window, taskbarEnabled()) @@ -322,7 +323,7 @@ void SetupTrayContent(not_null container) { } #ifndef OS_WIN_STORE - if (cPlatform() == dbipWindows) { + if (Platform::IsWindows()) { const auto minimizedToggled = [] { return cStartMinimized() && !Global::LocalPasscode(); }; diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index fbac5a6e43..222654b96a 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -32,6 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/file_utilities.h" #include "data/data_session.h" #include "chat_helpers/emoji_sets_manager.h" +#include "platform/platform_info.h" #include "support/support_common.h" #include "support/support_templates.h" #include "auth_session.h" @@ -527,7 +528,7 @@ void SetupMessages(not_null container) { add(SendByType::Enter, lng_settings_send_enter); add( SendByType::CtrlEnter, - ((cPlatform() == dbipMac || cPlatform() == dbipMacOld) + (Platform::IsMac() ? lng_settings_send_cmdenter : lng_settings_send_ctrlenter)); diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index 2526119cf6..2db069bb7d 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "window/notifications_manager.h" #include "platform/platform_notifications_manager.h" +#include "platform/platform_info.h" #include "mainwindow.h" #include "core/application.h" #include "auth_session.h" @@ -599,10 +600,9 @@ void SetupNotificationsContent(not_null container) { const auto nativeKey = [&] { if (!Platform::Notifications::Supported()) { return LangKey(); - } else if (cPlatform() == dbipWindows) { + } else if (Platform::IsWindows()) { return lng_settings_use_windows; - } else if (cPlatform() == dbipLinux32 - || cPlatform() == dbipLinux64) { + } else if (Platform::IsLinux()) { return lng_settings_use_native_notifications; } return LangKey(); @@ -619,7 +619,7 @@ void SetupNotificationsContent(not_null container) { return addCheckbox(nativeKey, Global::NativeNotifications()); }(); - const auto advancedSlide = (cPlatform() != dbipMac) + const auto advancedSlide = !Platform::IsMac10_8OrGreater() ? container->add( object_ptr>( container, diff --git a/Telegram/SourceFiles/ui/text/text.cpp b/Telegram/SourceFiles/ui/text/text.cpp index ba656f4c3a..067c7fbeea 100644 --- a/Telegram/SourceFiles/ui/text/text.cpp +++ b/Telegram/SourceFiles/ui/text/text.cpp @@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_block.h" #include "ui/emoji_config.h" #include "lang/lang_keys.h" -#include "platform/platform_specific.h" +#include "platform/platform_info.h" #include "boxes/confirm_box.h" #include "mainwindow.h" @@ -27,25 +27,24 @@ inline int32 countBlockHeight(const ITextBlock *b, const style::TextStyle *st) { } // namespace bool chIsBad(QChar ch) { -#ifdef OS_MAC_OLD - if (cIsSnowLeopard() && (ch == 8207 || ch == 8206 || ch == 8288)) { - return true; - } -#endif // OS_MAC_OLD return (ch == 0) || (ch >= 8232 && ch < 8237) || (ch >= 65024 && ch < 65040 && ch != 65039) || (ch >= 127 && ch < 160 && ch != 156) + || (Platform::IsMac() + && !Platform::IsMac10_7OrGreater() + && (ch == 8207 || ch == 8206 || ch == 8288)) + // qt harfbuzz crash see https://github.com/telegramdesktop/tdesktop/issues/4551 - || (cPlatform() == dbipMac && ch == 6158) + || (Platform::IsMac() && ch == 6158) // tmp hack see https://bugreports.qt.io/browse/QTBUG-48910 - || (cPlatform() == dbipMac - && ch >= 0x0B00 + || (Platform::IsMac10_11OrGreater() + && !Platform::IsMac10_12OrGreater() + && ch >= 0x0B00 && ch <= 0x0B7F - && chIsDiac(ch) - && cIsElCapitan()); + && chIsDiac(ch)); } QString textcmdSkipBlock(ushort w, ushort h) { @@ -439,7 +438,7 @@ public: bool skip = false, isNewLine = multiline && chIsNewline(ch), isSpace = chIsSpace(ch), isDiac = chIsDiac(ch), isTilde = checkTilde && (ch == '~'); if (chIsBad(ch) || ch.isLowSurrogate()) { skip = true; - } else if (ch == 0xFE0F && (cPlatform() == dbipMac || cPlatform() == dbipMacOld)) { + } else if (ch == 0xFE0F && Platform::IsMac()) { // Some sequences like 0x0E53 0xFE0F crash OS X harfbuzz text processing :( skip = true; } else if (isDiac) { diff --git a/Telegram/SourceFiles/ui/twidget.cpp b/Telegram/SourceFiles/ui/twidget.cpp index d40813859b..3113e597b4 100644 --- a/Telegram/SourceFiles/ui/twidget.cpp +++ b/Telegram/SourceFiles/ui/twidget.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "core/application.h" +#include "platform/platform_info.h" namespace Fonts { namespace { @@ -134,7 +135,7 @@ void CreateWidgetStateRecursive(not_null target) { if (!target->isWindow()) { CreateWidgetStateRecursive(target->parentWidget()); WidgetCreator::Create(target); - } else if (!cIsSnowLeopard()) { + } else if (!Platform::IsMac() || Platform::IsMac10_7OrGreater()) { WidgetCreator::Create(target); } } diff --git a/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp b/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp index 1a7e56c981..b6b699693d 100644 --- a/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp +++ b/Telegram/SourceFiles/ui/widgets/continuous_sliders.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/continuous_sliders.h" #include "base/timer.h" +#include "platform/platform_info.h" namespace Ui { namespace { @@ -113,7 +114,7 @@ void ContinuousSlider::wheelEvent(QWheelEvent *e) { constexpr auto coef = 1. / (step * 10.); auto deltaX = e->angleDelta().x(), deltaY = e->angleDelta().y(); - if (cPlatform() == dbipMac || cPlatform() == dbipMacOld) { + if (Platform::IsMac()) { deltaY *= -1; } else { deltaX *= -1; diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.cpp b/Telegram/SourceFiles/ui/widgets/input_fields.cpp index 0ae15328c8..8111d839a4 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "emoji_suggestions_data.h" #include "chat_helpers/emoji_suggestions_helper.h" #include "chat_helpers/message_field.h" // ConvertTextTagsToEntities +#include "platform/platform_info.h" #include "window/themes/window_theme.h" #include "lang/lang_keys.h" #include "data/data_user.h" @@ -2580,7 +2581,7 @@ bool InputField::ShouldSubmit( void InputField::keyPressEventInner(QKeyEvent *e) { bool shift = e->modifiers().testFlag(Qt::ShiftModifier), alt = e->modifiers().testFlag(Qt::AltModifier); - bool macmeta = (cPlatform() == dbipMac || cPlatform() == dbipMacOld) && e->modifiers().testFlag(Qt::ControlModifier) && !e->modifiers().testFlag(Qt::MetaModifier) && !e->modifiers().testFlag(Qt::AltModifier); + bool macmeta = Platform::IsMac() && e->modifiers().testFlag(Qt::ControlModifier) && !e->modifiers().testFlag(Qt::MetaModifier) && !e->modifiers().testFlag(Qt::AltModifier); bool ctrl = e->modifiers().testFlag(Qt::ControlModifier) || e->modifiers().testFlag(Qt::MetaModifier); bool enterSubmit = (_mode != Mode::MultiLine) || ShouldSubmit(_submitSettings, e->modifiers()); diff --git a/Telegram/SourceFiles/ui/widgets/popup_menu.cpp b/Telegram/SourceFiles/ui/widgets/popup_menu.cpp index 207653f72f..65b8cd4629 100644 --- a/Telegram/SourceFiles/ui/widgets/popup_menu.cpp +++ b/Telegram/SourceFiles/ui/widgets/popup_menu.cpp @@ -9,20 +9,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/shadow.h" #include "ui/image/image_prepare.h" +#include "platform/platform_info.h" #include "platform/platform_specific.h" #include "mainwindow.h" #include "core/application.h" #include "lang/lang_keys.h" namespace Ui { -namespace { - -bool InactiveMacApplication() { - return (cPlatform() == dbipMac || cPlatform() == dbipMacOld) - && !Platform::IsApplicationActive(); -} - -} // namespace PopupMenu::PopupMenu(QWidget *parent, const style::PopupMenu &st) : RpWidget(parent) @@ -430,7 +423,7 @@ void PopupMenu::popup(const QPoint &p) { } void PopupMenu::showMenu(const QPoint &p, PopupMenu *parent, TriggeredSource source) { - if (!parent && InactiveMacApplication()) { + if (!parent && Platform::IsMac() && !Platform::IsApplicationActive()) { _hiding = false; _a_opacity.stop(); _a_show.stop(); diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 9d9a4f9a99..d90974d292 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "platform/platform_window_title.h" +#include "platform/platform_info.h" #include "history/history.h" #include "window/themes/window_theme.h" #include "window/window_controller.h" @@ -26,10 +27,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_boxes.h" namespace Window { +namespace { constexpr auto kInactivePressTimeout = crl::time(200); constexpr auto kSaveWindowPositionTimeout = crl::time(1000); +} // namespace + QImage LoadLogo() { return QImage(qsl(":/gui/art/logo_256.png")); } @@ -96,7 +100,7 @@ QIcon CreateOfficialIcon() { QIcon CreateIcon() { auto result = CreateOfficialIcon(); - if (cPlatform() == dbipLinux32 || cPlatform() == dbipLinux64) { + if (Platform::IsLinux()) { return QIcon::fromTheme("telegram", result); } return result; @@ -229,7 +233,7 @@ bool MainWindow::hideNoQuit() { Ui::showChatsList(); return true; } - } else if (cPlatform() == dbipMac || cPlatform() == dbipMacOld) { + } else if (Platform::IsMac()) { closeWithoutDestroy(); updateIsActive(Global::OfflineBlurTimeout()); updateGlobalMenu(); @@ -335,9 +339,14 @@ HitTestResult MainWindow::hitTest(const QPoint &p) const { return Window::HitTestResult::None; } +int MainWindow::computeMinHeight() const { + const auto title = _title ? _title->height() : 0; + return title + st::windowMinHeight; +} + void MainWindow::initSize() { setMinimumWidth(st::windowMinWidth); - setMinimumHeight((_title ? _title->height() : 0) + st::windowMinHeight); + setMinimumHeight(computeMinHeight()); auto position = cWindowPos(); DEBUG_LOG(("Window Pos: Initializing first %1, %2, %3, %4 (maximized %5)").arg(position.x).arg(position.y).arg(position.w).arg(position.h).arg(Logs::b(position.maximized))); diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index 2d1aa02089..f3c4ce8155 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -158,6 +158,8 @@ private: void showTermsDecline(); void showTermsDelete(); + int computeMinHeight() const; + base::Timer _positionUpdatedTimer; bool _positionInited = false; diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index bd8dc1a67e..06185f4283 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -564,6 +564,8 @@ <(src_loc)/platform/linux/linux_libs.h <(src_loc)/platform/linux/file_utilities_linux.cpp <(src_loc)/platform/linux/file_utilities_linux.h +<(src_loc)/platform/linux/info_linux.cpp +<(src_loc)/platform/linux/info_linux.h <(src_loc)/platform/linux/launcher_linux.cpp <(src_loc)/platform/linux/launcher_linux.h <(src_loc)/platform/linux/main_window_linux.cpp @@ -574,6 +576,8 @@ <(src_loc)/platform/linux/specific_linux.h <(src_loc)/platform/mac/file_utilities_mac.mm <(src_loc)/platform/mac/file_utilities_mac.h +<(src_loc)/platform/mac/info_mac.mm +<(src_loc)/platform/mac/info_mac.h <(src_loc)/platform/mac/launcher_mac.mm <(src_loc)/platform/mac/launcher_mac.h <(src_loc)/platform/mac/mac_iconv_helper.c @@ -595,6 +599,8 @@ <(src_loc)/platform/win/audio_win.h <(src_loc)/platform/win/file_utilities_win.cpp <(src_loc)/platform/win/file_utilities_win.h +<(src_loc)/platform/win/info_win.cpp +<(src_loc)/platform/win/info_win.h <(src_loc)/platform/win/launcher_win.cpp <(src_loc)/platform/win/launcher_win.h <(src_loc)/platform/win/main_window_win.cpp @@ -615,6 +621,7 @@ <(src_loc)/platform/win/wrapper_wrl_implements_h.h <(src_loc)/platform/platform_audio.h <(src_loc)/platform/platform_file_utilities.h +<(src_loc)/platform/platform_info.h <(src_loc)/platform/platform_launcher.h <(src_loc)/platform/platform_main_window.h <(src_loc)/platform/platform_notifications_manager.h