From 1f1cd35d573f5d50370b922d94ac6ee64f7fb7a9 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 25 Feb 2023 21:22:36 +0400 Subject: [PATCH] videoplayer cheat code -> experimental setting --- Telegram/SourceFiles/data/data_document.cpp | 5 ++++- .../SourceFiles/data/data_document_resolver.cpp | 10 +++++++++- Telegram/SourceFiles/data/data_document_resolver.h | 2 ++ Telegram/SourceFiles/settings.cpp | 1 - Telegram/SourceFiles/settings.h | 1 - Telegram/SourceFiles/settings/settings_codes.cpp | 13 ------------- .../SourceFiles/settings/settings_experimental.cpp | 2 ++ .../storage/details/storage_settings_scheme.cpp | 4 +--- .../storage/details/storage_settings_scheme.h | 2 +- Telegram/SourceFiles/storage/storage_account.cpp | 1 - 10 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 8009b808b..a1d8539e6 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -32,6 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "platform/platform_file_utilities.h" #include "base/platform/base_platform_info.h" +#include "base/options.h" #include "history/history.h" #include "history/history_item.h" #include "history/view/media/history_view_gif.h" @@ -1312,10 +1313,12 @@ bool DocumentData::useStreamingLoader() const { bool DocumentData::canBeStreamed(HistoryItem *item) const { // Streaming couldn't be used with external player // Maybe someone brave will implement this once upon a time... + static const auto &ExternalVideoPlayer = base::options::lookup( + Data::kOptionExternalVideoPlayer); return hasRemoteLocation() && supportsStreaming() && (!isVideoFile() - || !cUseExternalVideoPlayer() + || !ExternalVideoPlayer.value() || (item && !item->allowsForward())); } diff --git a/Telegram/SourceFiles/data/data_document_resolver.cpp b/Telegram/SourceFiles/data/data_document_resolver.cpp index d4c5fe490..2a03aaa7c 100644 --- a/Telegram/SourceFiles/data/data_document_resolver.cpp +++ b/Telegram/SourceFiles/data/data_document_resolver.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "data/data_document_resolver.h" +#include "base/options.h" #include "base/platform/base_platform_info.h" #include "ui/boxes/confirm_box.h" #include "core/application.h" @@ -36,6 +37,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Data { namespace { +base::options::toggle OptionExternalVideoPlayer({ + .id = kOptionExternalVideoPlayer, + .name = "External video player", +}); + void ConfirmDontWarnBox( not_null box, rpl::producer &&text, @@ -117,6 +123,8 @@ void LaunchWithWarning( } // namespace +const char kOptionExternalVideoPlayer[] = "external-video-player"; + QString FileExtension(const QString &filepath) { const auto reversed = ranges::views::reverse(filepath); const auto last = ranges::find_first_of(reversed, ".\\/"); @@ -241,7 +249,7 @@ void ResolveDocument( const auto msgId = item ? item->fullId() : FullMsgId(); const auto showDocument = [&] { - if (cUseExternalVideoPlayer() + if (OptionExternalVideoPlayer.value() && document->isVideoFile() && !document->filepath().isEmpty()) { File::Launch(document->location(false).fname); diff --git a/Telegram/SourceFiles/data/data_document_resolver.h b/Telegram/SourceFiles/data/data_document_resolver.h index 65a76bf19..9931da3e8 100644 --- a/Telegram/SourceFiles/data/data_document_resolver.h +++ b/Telegram/SourceFiles/data/data_document_resolver.h @@ -20,6 +20,8 @@ namespace Data { class DocumentMedia; +extern const char kOptionExternalVideoPlayer[]; + [[nodiscard]] QString FileExtension(const QString &filepath); // [[nodiscard]] bool IsValidMediaFile(const QString &filepath); [[nodiscard]] bool IsExecutableName(const QString &filepath); diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index c4b11a726..e546b14d3 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -29,7 +29,6 @@ bool gStartMinimized = false; bool gStartInTray = false; bool gAutoStart = false; bool gSendToMenu = false; -bool gUseExternalVideoPlayer = false; bool gAutoUpdate = true; LaunchMode gLaunchMode = LaunchModeNormal; bool gSeenTrayTooltip = false; diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index 28ca676e4..298283651 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -38,7 +38,6 @@ DeclareSetting(bool, AutoStart); DeclareSetting(bool, StartMinimized); DeclareSetting(bool, StartInTray); DeclareSetting(bool, SendToMenu); -DeclareSetting(bool, UseExternalVideoPlayer); enum LaunchMode { LaunchModeNormal = 0, LaunchModeAutoStart, diff --git a/Telegram/SourceFiles/settings/settings_codes.cpp b/Telegram/SourceFiles/settings/settings_codes.cpp index d1333b2bc..54af5b7b2 100644 --- a/Telegram/SourceFiles/settings/settings_codes.cpp +++ b/Telegram/SourceFiles/settings/settings_codes.cpp @@ -116,19 +116,6 @@ auto GenerateCodes() { } }); }); - codes.emplace(u"videoplayer"_q, [](SessionController *window) { - if (!window) { - return; - } - auto text = cUseExternalVideoPlayer() - ? u"Use internal video player?"_q - : u"Use external video player?"_q; - Ui::show(Ui::MakeConfirmBox({ text, [=] { - cSetUseExternalVideoPlayer(!cUseExternalVideoPlayer()); - window->session().saveSettingsDelayed(); - Ui::hideLayer(); - } })); - }); codes.emplace(u"endpoints"_q, [](SessionController *window) { if (!Core::App().domain().started()) { return; diff --git a/Telegram/SourceFiles/settings/settings_experimental.cpp b/Telegram/SourceFiles/settings/settings_experimental.cpp index e0266e7a3..9c9f3ccb6 100644 --- a/Telegram/SourceFiles/settings/settings_experimental.cpp +++ b/Telegram/SourceFiles/settings/settings_experimental.cpp @@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/notifications_manager.h" #include "settings/settings_common.h" #include "storage/localimageloader.h" +#include "data/data_document_resolver.h" #include "styles/style_settings.h" #include "styles/style_layers.h" @@ -148,6 +149,7 @@ void SetupExperimental( addToggle(kOptionAutoScrollInactiveChat); addToggle(Window::Notifications::kOptionGNotification); addToggle(Core::kOptionFreeType); + addToggle(Data::kOptionExternalVideoPlayer); } } // namespace diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp index 77ae93264..0736d32d8 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp @@ -192,12 +192,10 @@ bool ReadSetting( cSetSendToMenu(v == 1); } break; - case dbiUseExternalVideoPlayer: { + case dbiUseExternalVideoPlayerOld: { qint32 v; stream >> v; if (!CheckStreamStatus(stream)) return false; - - cSetUseExternalVideoPlayer(v == 1); } break; case dbiCacheSettingsOld: { diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.h b/Telegram/SourceFiles/storage/details/storage_settings_scheme.h index 1e62ec6f9..2220c22cf 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.h +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.h @@ -140,7 +140,7 @@ enum { dbiNotificationsCornerOld = 0x46, dbiThemeKeyOld = 0x47, dbiDialogsWidthRatioOld = 0x48, - dbiUseExternalVideoPlayer = 0x49, + dbiUseExternalVideoPlayerOld = 0x49, dbiDcOptionsOld = 0x4a, dbiMtpAuthorization = 0x4b, dbiLastSeenWarningSeenOld = 0x4c, diff --git a/Telegram/SourceFiles/storage/storage_account.cpp b/Telegram/SourceFiles/storage/storage_account.cpp index 5cb5ac046..e85528403 100644 --- a/Telegram/SourceFiles/storage/storage_account.cpp +++ b/Telegram/SourceFiles/storage/storage_account.cpp @@ -860,7 +860,6 @@ void Account::writeSessionSettings(Main::SessionSettings *stored) { } EncryptedDescriptor data(size); - data.stream << quint32(dbiUseExternalVideoPlayer) << qint32(cUseExternalVideoPlayer()); data.stream << quint32(dbiCacheSettings) << qint64(_cacheTotalSizeLimit) << qint32(_cacheTotalTimeLimit) << qint64(_cacheBigFileTotalSizeLimit) << qint32(_cacheBigFileTotalTimeLimit); if (!userData.isEmpty()) { data.stream << quint32(dbiSessionSettings) << userData;