From c68601d6c27d76ec3909b04a951a29d1cf8cb301 Mon Sep 17 00:00:00 2001 From: ksooo <3226626+ksooo@users.noreply.github.com> Date: Fri, 8 Dec 2023 10:48:51 +0100 Subject: [PATCH 1/2] [video][interfaces][pvr] Consolidate VIDEO::GUILIB::PlayAction and VIDEO::GUILIB::SelectAction -> VIDEO::GUILIB::Action. --- xbmc/interfaces/builtins/PlayerBuiltins.cpp | 6 +-- xbmc/pvr/guilib/PVRGUIActionsPlayback.cpp | 6 +-- xbmc/video/ContextMenus.cpp | 4 +- xbmc/video/dialogs/GUIDialogVideoInfo.cpp | 7 ++- xbmc/video/guilib/CMakeLists.txt | 3 +- xbmc/video/guilib/VideoAction.h | 29 +++++++++++ xbmc/video/guilib/VideoPlayAction.h | 24 --------- .../video/guilib/VideoPlayActionProcessor.cpp | 24 ++++----- xbmc/video/guilib/VideoPlayActionProcessor.h | 8 +-- xbmc/video/guilib/VideoSelectAction.h | 29 ----------- .../guilib/VideoSelectActionProcessor.cpp | 52 +++++++++---------- .../video/guilib/VideoSelectActionProcessor.h | 10 ++-- xbmc/video/windows/GUIWindowVideoBase.cpp | 12 ++--- xbmc/video/windows/GUIWindowVideoBase.h | 4 +- 14 files changed, 96 insertions(+), 122 deletions(-) create mode 100644 xbmc/video/guilib/VideoAction.h delete mode 100644 xbmc/video/guilib/VideoPlayAction.h delete mode 100644 xbmc/video/guilib/VideoSelectAction.h diff --git a/xbmc/interfaces/builtins/PlayerBuiltins.cpp b/xbmc/interfaces/builtins/PlayerBuiltins.cpp index 01ee12c1c5f93..25e6f9c2260dd 100644 --- a/xbmc/interfaces/builtins/PlayerBuiltins.cpp +++ b/xbmc/interfaces/builtins/PlayerBuiltins.cpp @@ -513,13 +513,13 @@ int PlayOrQueueMedia(const std::vector& params, bool forcePlay) if (askToResume) { - const VIDEO::GUILIB::SelectAction action = + const VIDEO::GUILIB::Action action = VIDEO::GUILIB::CVideoSelectActionProcessorBase::ChoosePlayOrResume(item); - if (action == VIDEO::GUILIB::SELECT_ACTION_RESUME) + if (action == VIDEO::GUILIB::ACTION_RESUME) { item.SetStartOffset(STARTOFFSET_RESUME); } - else if (action != VIDEO::GUILIB::SELECT_ACTION_PLAY) + else if (action != VIDEO::GUILIB::ACTION_PLAY_FROM_BEGINNING) { // The Resume dialog was closed without any choice return false; diff --git a/xbmc/pvr/guilib/PVRGUIActionsPlayback.cpp b/xbmc/pvr/guilib/PVRGUIActionsPlayback.cpp index 4e834af7245ca..504351698a883 100644 --- a/xbmc/pvr/guilib/PVRGUIActionsPlayback.cpp +++ b/xbmc/pvr/guilib/PVRGUIActionsPlayback.cpp @@ -60,13 +60,13 @@ bool CPVRGUIActionsPlayback::CheckResumeRecording(const CFileItem& item) const { bool bPlayIt(true); - const VIDEO::GUILIB::SelectAction action = + const VIDEO::GUILIB::Action action = VIDEO::GUILIB::CVideoSelectActionProcessorBase::ChoosePlayOrResume(item); - if (action == VIDEO::GUILIB::SELECT_ACTION_RESUME) + if (action == VIDEO::GUILIB::ACTION_RESUME) { const_cast(&item)->SetStartOffset(STARTOFFSET_RESUME); } - else if (action == VIDEO::GUILIB::SELECT_ACTION_PLAY) + else if (action == VIDEO::GUILIB::ACTION_PLAY_FROM_BEGINNING) { const_cast(&item)->SetStartOffset(0); } diff --git a/xbmc/video/ContextMenus.cpp b/xbmc/video/ContextMenus.cpp index 41282845799a9..ef7332058734b 100644 --- a/xbmc/video/ContextMenus.cpp +++ b/xbmc/video/ContextMenus.cpp @@ -315,9 +315,9 @@ void SetPathAndPlay(const std::shared_ptr& item, const std::string& p CVideoPlayActionProcessor proc{item, player}; if (resume && (item->GetStartOffset() == STARTOFFSET_RESUME || VIDEO_UTILS::GetItemResumeInformation(*item).isResumable)) - proc.Process(VIDEO::GUILIB::PLAY_ACTION_RESUME); + proc.Process(VIDEO::GUILIB::ACTION_RESUME); else - proc.Process(VIDEO::GUILIB::PLAY_ACTION_PLAY_FROM_BEGINNING); + proc.Process(VIDEO::GUILIB::ACTION_PLAY_FROM_BEGINNING); item->ClearProperty("prohibit_choose_video_version"); } diff --git a/xbmc/video/dialogs/GUIDialogVideoInfo.cpp b/xbmc/video/dialogs/GUIDialogVideoInfo.cpp index 08e7a1579f03c..a76286d7117fb 100644 --- a/xbmc/video/dialogs/GUIDialogVideoInfo.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoInfo.cpp @@ -67,7 +67,6 @@ using namespace XFILE::VIDEODATABASEDIRECTORY; using namespace XFILE; using namespace KODI::MESSAGING; -using namespace VIDEO::GUILIB; #define CONTROL_IMAGE 3 #define CONTROL_TEXTAREA 4 @@ -712,7 +711,7 @@ void CGUIDialogVideoInfo::ClearCastList() namespace { -class CVideoPlayActionProcessor : public CVideoPlayActionProcessorBase +class CVideoPlayActionProcessor : public VIDEO::GUILIB::CVideoPlayActionProcessorBase { public: explicit CVideoPlayActionProcessor(const std::shared_ptr& item) @@ -791,7 +790,7 @@ void CGUIDialogVideoInfo::Play(bool resume) if (resume) { CVideoPlayActionProcessor proc{m_movieItem}; - proc.Process(PLAY_ACTION_RESUME); + proc.Process(VIDEO::GUILIB::ACTION_RESUME); } else { @@ -799,7 +798,7 @@ void CGUIDialogVideoInfo::Play(bool resume) { // if dialog has a resume button, play button has always the purpose to start from beginning CVideoPlayActionProcessor proc{m_movieItem}; - proc.Process(PLAY_ACTION_PLAY_FROM_BEGINNING); + proc.Process(VIDEO::GUILIB::ACTION_PLAY_FROM_BEGINNING); } else { diff --git a/xbmc/video/guilib/CMakeLists.txt b/xbmc/video/guilib/CMakeLists.txt index c5226897c43b1..a9532706240d0 100644 --- a/xbmc/video/guilib/CMakeLists.txt +++ b/xbmc/video/guilib/CMakeLists.txt @@ -2,9 +2,8 @@ set(SOURCES VideoPlayActionProcessor.cpp VideoSelectActionProcessor.cpp VideoActionProcessorHelper.cpp) -set(HEADERS VideoPlayAction.h +set(HEADERS VideoAction.h VideoPlayActionProcessor.h - VideoSelectAction.h VideoSelectActionProcessor.h VideoActionProcessorHelper.h) diff --git a/xbmc/video/guilib/VideoAction.h b/xbmc/video/guilib/VideoAction.h new file mode 100644 index 0000000000000..d2efd86d3c2a4 --- /dev/null +++ b/xbmc/video/guilib/VideoAction.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2023 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +namespace VIDEO +{ +namespace GUILIB +{ +// Note: Do not change the numerical values of the elements. Some of them are used as values for +// the integer settings SETTING_MYVIDEOS_SELECTACTION and SETTING_MYVIDEOS_PLAYACTION. +enum Action +{ + ACTION_CHOOSE = 0, + ACTION_PLAY_OR_RESUME = 1, // if resume is possible, ask user. play from beginning otherwise + ACTION_RESUME = 2, // resume if possibly, play from beginning otherwise + ACTION_INFO = 3, + ACTION_MORE = 4, + ACTION_PLAY_FROM_BEGINNING = 5, // play from beginning, also if resume would be possible + ACTION_PLAYPART = 6, + ACTION_QUEUE = 7, +}; +} // namespace GUILIB +} // namespace VIDEO diff --git a/xbmc/video/guilib/VideoPlayAction.h b/xbmc/video/guilib/VideoPlayAction.h deleted file mode 100644 index a5668756028b1..0000000000000 --- a/xbmc/video/guilib/VideoPlayAction.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2023 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#pragma once - -namespace VIDEO -{ -namespace GUILIB -{ -// Note: Do not change the numerical values of the elements. Some of them are used as values for -// the integer setting SETTING_MYVIDEOS_PLAYACTION. -enum PlayAction -{ - PLAY_ACTION_PLAY_OR_RESUME = 1, // if resume is possible, ask user. play from beginning otherwise - PLAY_ACTION_RESUME = 2, // resume if possibly, play from beginning otherwise - PLAY_ACTION_PLAY_FROM_BEGINNING = 5, // play from beginning, also if resume would be possible -}; -} // namespace GUILIB -} // namespace VIDEO diff --git a/xbmc/video/guilib/VideoPlayActionProcessor.cpp b/xbmc/video/guilib/VideoPlayActionProcessor.cpp index 7d508dca82755..2f59154603c02 100644 --- a/xbmc/video/guilib/VideoPlayActionProcessor.cpp +++ b/xbmc/video/guilib/VideoPlayActionProcessor.cpp @@ -20,9 +20,9 @@ using namespace VIDEO::GUILIB; -PlayAction CVideoPlayActionProcessorBase::GetDefaultPlayAction() +Action CVideoPlayActionProcessorBase::GetDefaultPlayAction() { - return static_cast(CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt( + return static_cast(CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt( CSettings::SETTING_MYVIDEOS_PLAYACTION)); } @@ -31,7 +31,7 @@ bool CVideoPlayActionProcessorBase::Process() return Process(GetDefaultPlayAction()); } -bool CVideoPlayActionProcessorBase::Process(PlayAction playAction) +bool CVideoPlayActionProcessorBase::Process(Action playAction) { m_userCancelled = false; @@ -52,9 +52,9 @@ bool CVideoPlayActionProcessorBase::Process(PlayAction playAction) switch (playAction) { - case PLAY_ACTION_PLAY_OR_RESUME: + case ACTION_PLAY_OR_RESUME: { - const VIDEO::GUILIB::PlayAction action = ChoosePlayOrResume(); + const Action action = ChoosePlayOrResume(); if (action < 0) { m_userCancelled = true; @@ -64,10 +64,10 @@ bool CVideoPlayActionProcessorBase::Process(PlayAction playAction) return Process(action); } - case PLAY_ACTION_RESUME: + case ACTION_RESUME: return OnResumeSelected(); - case PLAY_ACTION_PLAY_FROM_BEGINNING: + case ACTION_PLAY_FROM_BEGINNING: return OnPlaySelected(); default: @@ -76,19 +76,19 @@ bool CVideoPlayActionProcessorBase::Process(PlayAction playAction) return false; // We did not handle the action. } -PlayAction CVideoPlayActionProcessorBase::ChoosePlayOrResume() +Action CVideoPlayActionProcessorBase::ChoosePlayOrResume() { - PlayAction action = PLAY_ACTION_PLAY_FROM_BEGINNING; + Action action = ACTION_PLAY_FROM_BEGINNING; const std::string resumeString = VIDEO_UTILS::GetResumeString(*m_item); if (!resumeString.empty()) { CContextButtons choices; - choices.Add(PLAY_ACTION_RESUME, resumeString); - choices.Add(PLAY_ACTION_PLAY_FROM_BEGINNING, 12021); // Play from beginning + choices.Add(ACTION_RESUME, resumeString); + choices.Add(ACTION_PLAY_FROM_BEGINNING, 12021); // Play from beginning - action = static_cast(CGUIDialogContextMenu::ShowAndGetChoice(choices)); + action = static_cast(CGUIDialogContextMenu::ShowAndGetChoice(choices)); } return action; diff --git a/xbmc/video/guilib/VideoPlayActionProcessor.h b/xbmc/video/guilib/VideoPlayActionProcessor.h index 25753bc6d07e3..a09ffd30e8f83 100644 --- a/xbmc/video/guilib/VideoPlayActionProcessor.h +++ b/xbmc/video/guilib/VideoPlayActionProcessor.h @@ -8,7 +8,7 @@ #pragma once -#include "video/guilib/VideoPlayAction.h" +#include "video/guilib/VideoAction.h" #include @@ -29,10 +29,10 @@ class CVideoPlayActionProcessorBase } virtual ~CVideoPlayActionProcessorBase() = default; - static PlayAction GetDefaultPlayAction(); + static Action GetDefaultPlayAction(); bool Process(); - bool Process(PlayAction playAction); + bool Process(Action playAction); bool UserCancelled() const { return m_userCancelled; } @@ -45,7 +45,7 @@ class CVideoPlayActionProcessorBase private: CVideoPlayActionProcessorBase() = delete; - PlayAction ChoosePlayOrResume(); + Action ChoosePlayOrResume(); bool m_versionChecked{false}; const std::shared_ptr m_videoVersion; diff --git a/xbmc/video/guilib/VideoSelectAction.h b/xbmc/video/guilib/VideoSelectAction.h deleted file mode 100644 index 731e0cf35bbf1..0000000000000 --- a/xbmc/video/guilib/VideoSelectAction.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2023 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#pragma once - -namespace VIDEO -{ -namespace GUILIB -{ -// Note: Do not change the numerical values of the elements. Some of them are used as values for -// the integer setting SETTING_MYVIDEOS_SELECTACTION. -enum SelectAction -{ - SELECT_ACTION_CHOOSE = 0, - SELECT_ACTION_PLAY_OR_RESUME = 1, - SELECT_ACTION_RESUME = 2, - SELECT_ACTION_INFO = 3, - SELECT_ACTION_MORE = 4, - SELECT_ACTION_PLAY = 5, - SELECT_ACTION_PLAYPART = 6, - SELECT_ACTION_QUEUE = 7, -}; -} // namespace GUILIB -} // namespace VIDEO diff --git a/xbmc/video/guilib/VideoSelectActionProcessor.cpp b/xbmc/video/guilib/VideoSelectActionProcessor.cpp index 15fd6e5e4d602..3bab184d23ff5 100644 --- a/xbmc/video/guilib/VideoSelectActionProcessor.cpp +++ b/xbmc/video/guilib/VideoSelectActionProcessor.cpp @@ -26,9 +26,9 @@ using namespace VIDEO::GUILIB; -SelectAction CVideoSelectActionProcessorBase::GetDefaultSelectAction() +Action CVideoSelectActionProcessorBase::GetDefaultSelectAction() { - return static_cast(CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt( + return static_cast(CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt( CSettings::SETTING_MYVIDEOS_SELECTACTION)); } @@ -37,7 +37,7 @@ bool CVideoSelectActionProcessorBase::Process() return Process(GetDefaultSelectAction()); } -bool CVideoSelectActionProcessorBase::Process(SelectAction selectAction) +bool CVideoSelectActionProcessorBase::Process(Action selectAction) { CVideoActionProcessorHelper procHelper{m_item, m_videoVersion}; @@ -53,25 +53,25 @@ bool CVideoSelectActionProcessorBase::Process(SelectAction selectAction) switch (selectAction) { - case SELECT_ACTION_CHOOSE: + case ACTION_CHOOSE: { - const SelectAction action = ChooseVideoItemSelectAction(); + const Action action = ChooseVideoItemSelectAction(); if (action < 0) return true; // User cancelled the context menu. We're done. return Process(action); } - case SELECT_ACTION_PLAY_OR_RESUME: + case ACTION_PLAY_OR_RESUME: { - const SelectAction action = ChoosePlayOrResume(*m_item); + const Action action = ChoosePlayOrResume(*m_item); if (action < 0) return true; // User cancelled the select menu. We're done. return Process(action); } - case SELECT_ACTION_PLAYPART: + case ACTION_PLAYPART: { const unsigned int part = ChooseStackItemPartNumber(); if (part < 1) // part numbers are 1-based @@ -80,19 +80,19 @@ bool CVideoSelectActionProcessorBase::Process(SelectAction selectAction) return OnPlayPartSelected(part); } - case SELECT_ACTION_RESUME: + case ACTION_RESUME: return OnResumeSelected(); - case SELECT_ACTION_PLAY: + case ACTION_PLAY_FROM_BEGINNING: return OnPlaySelected(); - case SELECT_ACTION_QUEUE: + case ACTION_QUEUE: return OnQueueSelected(); - case SELECT_ACTION_INFO: + case ACTION_INFO: return OnInfoSelected(); - case SELECT_ACTION_MORE: + case ACTION_MORE: return OnMoreSelected(); default: @@ -124,42 +124,42 @@ unsigned int CVideoSelectActionProcessorBase::ChooseStackItemPartNumber() const return dialog->GetSelectedItem() + 1; // part numbers are 1-based } -SelectAction CVideoSelectActionProcessorBase::ChoosePlayOrResume(const CFileItem& item) +Action CVideoSelectActionProcessorBase::ChoosePlayOrResume(const CFileItem& item) { - SelectAction action = SELECT_ACTION_PLAY; + Action action = ACTION_PLAY_FROM_BEGINNING; const std::string resumeString = VIDEO_UTILS::GetResumeString(item); if (!resumeString.empty()) { CContextButtons choices; - choices.Add(SELECT_ACTION_RESUME, resumeString); - choices.Add(SELECT_ACTION_PLAY, 12021); // Play from beginning + choices.Add(ACTION_RESUME, resumeString); + choices.Add(ACTION_PLAY_FROM_BEGINNING, 12021); // Play from beginning - action = static_cast(CGUIDialogContextMenu::ShowAndGetChoice(choices)); + action = static_cast(CGUIDialogContextMenu::ShowAndGetChoice(choices)); } return action; } -SelectAction CVideoSelectActionProcessorBase::ChooseVideoItemSelectAction() const +Action CVideoSelectActionProcessorBase::ChooseVideoItemSelectAction() const { CContextButtons choices; const std::string resumeString = VIDEO_UTILS::GetResumeString(*m_item); if (!resumeString.empty()) { - choices.Add(SELECT_ACTION_RESUME, resumeString); - choices.Add(SELECT_ACTION_PLAY, 12021); // Play from beginning + choices.Add(ACTION_RESUME, resumeString); + choices.Add(ACTION_PLAY_FROM_BEGINNING, 12021); // Play from beginning } else { - choices.Add(SELECT_ACTION_PLAY, 208); // Play + choices.Add(ACTION_PLAY_FROM_BEGINNING, 208); // Play } - choices.Add(SELECT_ACTION_INFO, 22081); // Show information - choices.Add(SELECT_ACTION_QUEUE, 13347); // Queue item - choices.Add(SELECT_ACTION_MORE, 22082); // More + choices.Add(ACTION_INFO, 22081); // Show information + choices.Add(ACTION_QUEUE, 13347); // Queue item + choices.Add(ACTION_MORE, 22082); // More - return static_cast(CGUIDialogContextMenu::ShowAndGetChoice(choices)); + return static_cast(CGUIDialogContextMenu::ShowAndGetChoice(choices)); } diff --git a/xbmc/video/guilib/VideoSelectActionProcessor.h b/xbmc/video/guilib/VideoSelectActionProcessor.h index a154921166455..12332addb989f 100644 --- a/xbmc/video/guilib/VideoSelectActionProcessor.h +++ b/xbmc/video/guilib/VideoSelectActionProcessor.h @@ -8,7 +8,7 @@ #pragma once -#include "video/guilib/VideoSelectAction.h" +#include "video/guilib/VideoAction.h" #include @@ -29,12 +29,12 @@ class CVideoSelectActionProcessorBase } virtual ~CVideoSelectActionProcessorBase() = default; - static SelectAction GetDefaultSelectAction(); + static Action GetDefaultSelectAction(); bool Process(); - bool Process(SelectAction selectAction); + bool Process(Action selectAction); - static SelectAction ChoosePlayOrResume(const CFileItem& item); + static Action ChoosePlayOrResume(const CFileItem& item); protected: virtual bool OnPlayPartSelected(unsigned int part) = 0; @@ -48,7 +48,7 @@ class CVideoSelectActionProcessorBase private: CVideoSelectActionProcessorBase() = delete; - SelectAction ChooseVideoItemSelectAction() const; + Action ChooseVideoItemSelectAction() const; unsigned int ChooseStackItemPartNumber() const; bool m_versionChecked{false}; diff --git a/xbmc/video/windows/GUIWindowVideoBase.cpp b/xbmc/video/windows/GUIWindowVideoBase.cpp index 7e7ee38705ffc..6ad778a048263 100644 --- a/xbmc/video/windows/GUIWindowVideoBase.cpp +++ b/xbmc/video/windows/GUIWindowVideoBase.cpp @@ -607,7 +607,7 @@ class CVideoSelectActionProcessor : public CVideoSelectActionProcessorBase }; } // namespace -bool CGUIWindowVideoBase::OnFileAction(int iItem, SelectAction action, const std::string& player) +bool CGUIWindowVideoBase::OnFileAction(int iItem, Action action, const std::string& player) { const std::shared_ptr item = m_vecItems->Get(iItem); if (!item) @@ -754,13 +754,13 @@ class CVideoPlayActionProcessor : public CVideoPlayActionProcessorBase bool OnResumeSelected() override { m_item->SetStartOffset(STARTOFFSET_RESUME); - return m_window.OnFileAction(m_itemIndex, SELECT_ACTION_RESUME, m_player); + return m_window.OnFileAction(m_itemIndex, VIDEO::GUILIB::ACTION_RESUME, m_player); } bool OnPlaySelected() override { m_item->SetStartOffset(0); - return m_window.OnFileAction(m_itemIndex, SELECT_ACTION_PLAY, m_player); + return m_window.OnFileAction(m_itemIndex, VIDEO::GUILIB::ACTION_PLAY_FROM_BEGINNING, m_player); } private: @@ -851,13 +851,13 @@ bool CGUIWindowVideoBase::OnPlayStackPart(int itemIndex, unsigned int partNumber CDirectory::GetDirectory(path, parts, "", DIR_FLAG_DEFAULTS); const int value = CVideoSelectActionProcessor::ChoosePlayOrResume(*parts[partNumber - 1]); - if (value == SELECT_ACTION_RESUME) + if (value == VIDEO::GUILIB::ACTION_RESUME) { const VIDEO_UTILS::ResumeInformation resumeInfo = VIDEO_UTILS::GetItemResumeInformation(*parts[partNumber - 1]); item->SetStartOffset(resumeInfo.startOffset); } - else if (value != SELECT_ACTION_PLAY) + else if (value != VIDEO::GUILIB::ACTION_PLAY_FROM_BEGINNING) return false; // if not selected PLAY, then we changed our mind so return item->m_lStartPartNumber = partNumber; @@ -894,7 +894,7 @@ bool CGUIWindowVideoBase::OnContextButton(int itemNumber, CONTEXT_BUTTON button) } case CONTEXT_BUTTON_PLAY_PART: { - return OnFileAction(itemNumber, SELECT_ACTION_PLAYPART, ""); + return OnFileAction(itemNumber, VIDEO::GUILIB::ACTION_PLAYPART, ""); } case CONTEXT_BUTTON_PLAY_PARTYMODE: diff --git a/xbmc/video/windows/GUIWindowVideoBase.h b/xbmc/video/windows/GUIWindowVideoBase.h index 9916980d4ab17..1542ac4dcea7b 100644 --- a/xbmc/video/windows/GUIWindowVideoBase.h +++ b/xbmc/video/windows/GUIWindowVideoBase.h @@ -11,7 +11,7 @@ #include "playlists/PlayListTypes.h" #include "video/VideoDatabase.h" #include "video/VideoThumbLoader.h" -#include "video/guilib/VideoSelectAction.h" +#include "video/guilib/VideoAction.h" #include "windows/GUIMediaWindow.h" namespace @@ -95,7 +95,7 @@ class CGUIWindowVideoBase : public CGUIMediaWindow, public IBackgroundLoaderObse \param action the action to perform \return true if the action is performed, false otherwise */ - bool OnFileAction(int item, VIDEO::GUILIB::SelectAction action, const std::string& player); + bool OnFileAction(int item, VIDEO::GUILIB::Action action, const std::string& player); void OnRestartItem(int iItem, const std::string &player = ""); bool OnPlayOrResumeItem(int iItem, const std::string& player = ""); From 06418a134fda7ac57474f9a36e16d9ebf0c901c2 Mon Sep 17 00:00:00 2001 From: ksooo <3226626+ksooo@users.noreply.github.com> Date: Fri, 8 Dec 2023 14:51:39 +0100 Subject: [PATCH 2/2] [video] Derive VIDEO::GUILIB::CVideoSelectActionProcessorBase from VIDEO::GUILIB::CVideoPlayActionProcessorBase -> eliminate duplicate code. --- xbmc/favourites/GUIWindowFavourites.cpp | 4 +- xbmc/listproviders/DirectoryProvider.cpp | 4 +- xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp | 2 +- .../pvr/dialogs/GUIDialogPVRRecordingInfo.cpp | 2 +- xbmc/pvr/windows/GUIWindowPVRRecordings.cpp | 4 +- xbmc/video/ContextMenus.cpp | 6 +- xbmc/video/dialogs/GUIDialogVideoInfo.cpp | 6 +- xbmc/video/dialogs/GUIDialogVideoVersion.cpp | 2 +- .../video/guilib/VideoPlayActionProcessor.cpp | 42 ++++++------ xbmc/video/guilib/VideoPlayActionProcessor.h | 13 ++-- .../guilib/VideoSelectActionProcessor.cpp | 64 ++++--------------- .../video/guilib/VideoSelectActionProcessor.h | 30 ++++----- xbmc/video/windows/GUIWindowVideoBase.cpp | 4 +- 13 files changed, 70 insertions(+), 113 deletions(-) diff --git a/xbmc/favourites/GUIWindowFavourites.cpp b/xbmc/favourites/GUIWindowFavourites.cpp index 25989b364a080..10cfc0180f434 100644 --- a/xbmc/favourites/GUIWindowFavourites.cpp +++ b/xbmc/favourites/GUIWindowFavourites.cpp @@ -139,7 +139,7 @@ bool CGUIWindowFavourites::OnSelect(int itemIdx) if (targetItem.HasVideoInfoTag() && (!targetItem.m_bIsFolder || isPlayMedia)) { CVideoSelectActionProcessor proc{std::make_shared(targetItem)}; - if (proc.Process()) + if (proc.ProcessDefaultAction()) return true; } @@ -166,7 +166,7 @@ bool CGUIWindowFavourites::OnAction(const CAction& action) if (item->HasVideoInfoTag() || (item->m_bIsFolder && VIDEO_UTILS::IsItemPlayable(*item))) { CVideoPlayActionProcessor proc{item}; - if (proc.Process()) + if (proc.ProcessDefaultAction()) return true; } diff --git a/xbmc/listproviders/DirectoryProvider.cpp b/xbmc/listproviders/DirectoryProvider.cpp index f1f4228f5d971..2811ec1882cd1 100644 --- a/xbmc/listproviders/DirectoryProvider.cpp +++ b/xbmc/listproviders/DirectoryProvider.cpp @@ -564,7 +564,7 @@ bool CDirectoryProvider::OnClick(const CGUIListItemPtr& item) if (targetItem.HasVideoInfoTag() && (!targetItem.m_bIsFolder || isPlayMedia)) { CVideoSelectActionProcessor proc{*this, std::make_shared(targetItem)}; - if (proc.Process()) + if (proc.ProcessDefaultAction()) return true; } @@ -595,7 +595,7 @@ bool CDirectoryProvider::OnPlay(const CGUIListItemPtr& item) (targetItem.m_bIsFolder && VIDEO_UTILS::IsItemPlayable(targetItem))) { CVideoPlayActionProcessor proc{std::make_shared(targetItem)}; - if (proc.Process()) + if (proc.ProcessDefaultAction()) return true; } diff --git a/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp b/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp index c3c20264e01ae..1605234bfe995 100644 --- a/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp +++ b/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp @@ -141,7 +141,7 @@ bool CGUIDialogPVRGuideInfo::OnClickButtonPlay(const CGUIMessage& message) if (recording) { CGUIPVRRecordingsPlayActionProcessor proc{std::make_shared(recording)}; - proc.Process(); + proc.ProcessDefaultAction(); if (proc.UserCancelled()) Open(); } diff --git a/xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.cpp b/xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.cpp index f6af16e05c07d..6019c3feb16ba 100644 --- a/xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.cpp +++ b/xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.cpp @@ -61,7 +61,7 @@ bool CGUIDialogPVRRecordingInfo::OnClickButtonPlay(const CGUIMessage& message) if (m_recordItem) { CGUIPVRRecordingsPlayActionProcessor proc{m_recordItem}; - proc.Process(); + proc.ProcessDefaultAction(); if (proc.UserCancelled()) Open(); } diff --git a/xbmc/pvr/windows/GUIWindowPVRRecordings.cpp b/xbmc/pvr/windows/GUIWindowPVRRecordings.cpp index a1164e640f0f0..3f545098dea14 100644 --- a/xbmc/pvr/windows/GUIWindowPVRRecordings.cpp +++ b/xbmc/pvr/windows/GUIWindowPVRRecordings.cpp @@ -351,7 +351,7 @@ bool CGUIWindowPVRRecordingsBase::OnMessage(CGUIMessage& message) if (!item->IsParentFolder() && message.GetParam1() == ACTION_PLAYER_PLAY) { CVideoPlayActionProcessor proc{item}; - bReturn = proc.Process(); + bReturn = proc.ProcessDefaultAction(); } else if (item->m_bIsFolder) { @@ -361,7 +361,7 @@ bool CGUIWindowPVRRecordingsBase::OnMessage(CGUIMessage& message) else { CVideoSelectActionProcessor proc(*this, item, iItem); - bReturn = proc.Process(); + bReturn = proc.ProcessDefaultAction(); } break; } diff --git a/xbmc/video/ContextMenus.cpp b/xbmc/video/ContextMenus.cpp index ef7332058734b..955ad2b3a1907 100644 --- a/xbmc/video/ContextMenus.cpp +++ b/xbmc/video/ContextMenus.cpp @@ -236,7 +236,7 @@ bool CVideoChooseVersion::Execute(const std::shared_ptr& item) const // force selection dialog, regardless of any settings like 'Select default video version' item->SetProperty("force_choose_video_version", true); CVideoSelectActionProcessor proc{item}; - const bool ret = proc.Process(); + const bool ret = proc.ProcessDefaultAction(); item->ClearProperty("force_choose_video_version"); return ret; } @@ -315,9 +315,9 @@ void SetPathAndPlay(const std::shared_ptr& item, const std::string& p CVideoPlayActionProcessor proc{item, player}; if (resume && (item->GetStartOffset() == STARTOFFSET_RESUME || VIDEO_UTILS::GetItemResumeInformation(*item).isResumable)) - proc.Process(VIDEO::GUILIB::ACTION_RESUME); + proc.ProcessAction(VIDEO::GUILIB::ACTION_RESUME); else - proc.Process(VIDEO::GUILIB::ACTION_PLAY_FROM_BEGINNING); + proc.ProcessAction(VIDEO::GUILIB::ACTION_PLAY_FROM_BEGINNING); item->ClearProperty("prohibit_choose_video_version"); } diff --git a/xbmc/video/dialogs/GUIDialogVideoInfo.cpp b/xbmc/video/dialogs/GUIDialogVideoInfo.cpp index a76286d7117fb..df4582d229fdc 100644 --- a/xbmc/video/dialogs/GUIDialogVideoInfo.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoInfo.cpp @@ -790,7 +790,7 @@ void CGUIDialogVideoInfo::Play(bool resume) if (resume) { CVideoPlayActionProcessor proc{m_movieItem}; - proc.Process(VIDEO::GUILIB::ACTION_RESUME); + proc.ProcessAction(VIDEO::GUILIB::ACTION_RESUME); } else { @@ -798,13 +798,13 @@ void CGUIDialogVideoInfo::Play(bool resume) { // if dialog has a resume button, play button has always the purpose to start from beginning CVideoPlayActionProcessor proc{m_movieItem}; - proc.Process(VIDEO::GUILIB::ACTION_PLAY_FROM_BEGINNING); + proc.ProcessAction(VIDEO::GUILIB::ACTION_PLAY_FROM_BEGINNING); } else { // play button acts according to default play action setting CVideoPlayActionProcessor proc{m_movieItem}; - proc.Process(); + proc.ProcessDefaultAction(); if (proc.UserCancelled()) { // The Resume dialog was closed without any choice diff --git a/xbmc/video/dialogs/GUIDialogVideoVersion.cpp b/xbmc/video/dialogs/GUIDialogVideoVersion.cpp index a8f380ab59ee4..800d4ff31181b 100644 --- a/xbmc/video/dialogs/GUIDialogVideoVersion.cpp +++ b/xbmc/video/dialogs/GUIDialogVideoVersion.cpp @@ -371,7 +371,7 @@ void CGUIDialogVideoVersion::Play() CloseAll(); CVideoPlayActionProcessor proc{m_videoItem, m_selectedVideoVersion}; - proc.Process(); + proc.ProcessDefaultAction(); } void CGUIDialogVideoVersion::Remove() diff --git a/xbmc/video/guilib/VideoPlayActionProcessor.cpp b/xbmc/video/guilib/VideoPlayActionProcessor.cpp index 2f59154603c02..bea41524d888e 100644 --- a/xbmc/video/guilib/VideoPlayActionProcessor.cpp +++ b/xbmc/video/guilib/VideoPlayActionProcessor.cpp @@ -20,48 +20,48 @@ using namespace VIDEO::GUILIB; -Action CVideoPlayActionProcessorBase::GetDefaultPlayAction() +Action CVideoPlayActionProcessorBase::GetDefaultAction() { return static_cast(CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt( CSettings::SETTING_MYVIDEOS_PLAYACTION)); } -bool CVideoPlayActionProcessorBase::Process() +bool CVideoPlayActionProcessorBase::ProcessDefaultAction() { - return Process(GetDefaultPlayAction()); + return ProcessAction(GetDefaultAction()); } -bool CVideoPlayActionProcessorBase::Process(Action playAction) +bool CVideoPlayActionProcessorBase::ProcessAction(Action action) { m_userCancelled = false; CVideoActionProcessorHelper procHelper{m_item, m_videoVersion}; - - if (!m_versionChecked) + const auto videoVersion{procHelper.ChooseVideoVersion()}; + if (videoVersion) + m_item = videoVersion; + else { - m_versionChecked = true; - const auto videoVersion{procHelper.ChooseVideoVersion()}; - if (videoVersion) - m_item = videoVersion; - else - { - m_userCancelled = true; - return true; // User cancelled the select menu. We're done. - } + m_userCancelled = true; + return true; // User cancelled the select menu. We're done. } - switch (playAction) + return Process(action); +} + +bool CVideoPlayActionProcessorBase::Process(Action action) +{ + switch (action) { case ACTION_PLAY_OR_RESUME: { - const Action action = ChoosePlayOrResume(); - if (action < 0) + const Action selectedAction = ChoosePlayOrResume(*m_item); + if (selectedAction < 0) { m_userCancelled = true; return true; // User cancelled the select menu. We're done. } - return Process(action); + return Process(selectedAction); } case ACTION_RESUME: @@ -76,11 +76,11 @@ bool CVideoPlayActionProcessorBase::Process(Action playAction) return false; // We did not handle the action. } -Action CVideoPlayActionProcessorBase::ChoosePlayOrResume() +Action CVideoPlayActionProcessorBase::ChoosePlayOrResume(const CFileItem& item) { Action action = ACTION_PLAY_FROM_BEGINNING; - const std::string resumeString = VIDEO_UTILS::GetResumeString(*m_item); + const std::string resumeString = VIDEO_UTILS::GetResumeString(item); if (!resumeString.empty()) { CContextButtons choices; diff --git a/xbmc/video/guilib/VideoPlayActionProcessor.h b/xbmc/video/guilib/VideoPlayActionProcessor.h index a09ffd30e8f83..33105be8ad018 100644 --- a/xbmc/video/guilib/VideoPlayActionProcessor.h +++ b/xbmc/video/guilib/VideoPlayActionProcessor.h @@ -29,14 +29,17 @@ class CVideoPlayActionProcessorBase } virtual ~CVideoPlayActionProcessorBase() = default; - static Action GetDefaultPlayAction(); - - bool Process(); - bool Process(Action playAction); + bool ProcessDefaultAction(); + bool ProcessAction(Action action); bool UserCancelled() const { return m_userCancelled; } + static Action ChoosePlayOrResume(const CFileItem& item); + protected: + virtual Action GetDefaultAction(); + virtual bool Process(Action action); + virtual bool OnResumeSelected() = 0; virtual bool OnPlaySelected() = 0; @@ -45,9 +48,7 @@ class CVideoPlayActionProcessorBase private: CVideoPlayActionProcessorBase() = delete; - Action ChoosePlayOrResume(); - bool m_versionChecked{false}; const std::shared_ptr m_videoVersion; }; } // namespace GUILIB diff --git a/xbmc/video/guilib/VideoSelectActionProcessor.cpp b/xbmc/video/guilib/VideoSelectActionProcessor.cpp index 3bab184d23ff5..4458115bbf329 100644 --- a/xbmc/video/guilib/VideoSelectActionProcessor.cpp +++ b/xbmc/video/guilib/VideoSelectActionProcessor.cpp @@ -22,7 +22,6 @@ #include "utils/Variant.h" #include "video/VideoInfoTag.h" #include "video/VideoUtils.h" -#include "video/guilib/VideoActionProcessorHelper.h" using namespace VIDEO::GUILIB; @@ -32,43 +31,28 @@ Action CVideoSelectActionProcessorBase::GetDefaultSelectAction() CSettings::SETTING_MYVIDEOS_SELECTACTION)); } -bool CVideoSelectActionProcessorBase::Process() +Action CVideoSelectActionProcessorBase::GetDefaultAction() { - return Process(GetDefaultSelectAction()); + return GetDefaultSelectAction(); } -bool CVideoSelectActionProcessorBase::Process(Action selectAction) +bool CVideoSelectActionProcessorBase::Process(Action action) { - CVideoActionProcessorHelper procHelper{m_item, m_videoVersion}; + if (CVideoPlayActionProcessorBase::Process(action)) + return true; - if (!m_versionChecked) - { - m_versionChecked = true; - const auto videoVersion{procHelper.ChooseVideoVersion()}; - if (videoVersion) - m_item = videoVersion; - else - return true; // User cancelled the select menu. We're done. - } - - switch (selectAction) + switch (action) { case ACTION_CHOOSE: { - const Action action = ChooseVideoItemSelectAction(); - if (action < 0) - return true; // User cancelled the context menu. We're done. - - return Process(action); - } - - case ACTION_PLAY_OR_RESUME: - { - const Action action = ChoosePlayOrResume(*m_item); - if (action < 0) + const Action selectedAction = ChooseVideoItemSelectAction(); + if (selectedAction < 0) + { + m_userCancelled = true; return true; // User cancelled the select menu. We're done. + } - return Process(action); + return Process(selectedAction); } case ACTION_PLAYPART: @@ -80,12 +64,6 @@ bool CVideoSelectActionProcessorBase::Process(Action selectAction) return OnPlayPartSelected(part); } - case ACTION_RESUME: - return OnResumeSelected(); - - case ACTION_PLAY_FROM_BEGINNING: - return OnPlaySelected(); - case ACTION_QUEUE: return OnQueueSelected(); @@ -124,24 +102,6 @@ unsigned int CVideoSelectActionProcessorBase::ChooseStackItemPartNumber() const return dialog->GetSelectedItem() + 1; // part numbers are 1-based } -Action CVideoSelectActionProcessorBase::ChoosePlayOrResume(const CFileItem& item) -{ - Action action = ACTION_PLAY_FROM_BEGINNING; - - const std::string resumeString = VIDEO_UTILS::GetResumeString(item); - if (!resumeString.empty()) - { - CContextButtons choices; - - choices.Add(ACTION_RESUME, resumeString); - choices.Add(ACTION_PLAY_FROM_BEGINNING, 12021); // Play from beginning - - action = static_cast(CGUIDialogContextMenu::ShowAndGetChoice(choices)); - } - - return action; -} - Action CVideoSelectActionProcessorBase::ChooseVideoItemSelectAction() const { CContextButtons choices; diff --git a/xbmc/video/guilib/VideoSelectActionProcessor.h b/xbmc/video/guilib/VideoSelectActionProcessor.h index 12332addb989f..11217df5a632d 100644 --- a/xbmc/video/guilib/VideoSelectActionProcessor.h +++ b/xbmc/video/guilib/VideoSelectActionProcessor.h @@ -8,7 +8,7 @@ #pragma once -#include "video/guilib/VideoAction.h" +#include "video/guilib/VideoPlayActionProcessor.h" #include @@ -18,41 +18,37 @@ namespace VIDEO { namespace GUILIB { -class CVideoSelectActionProcessorBase +class CVideoSelectActionProcessorBase : public CVideoPlayActionProcessorBase { public: - explicit CVideoSelectActionProcessorBase(const std::shared_ptr& item) : m_item(item) {} + explicit CVideoSelectActionProcessorBase(const std::shared_ptr& item) + : CVideoPlayActionProcessorBase(item) + { + } + CVideoSelectActionProcessorBase(const std::shared_ptr& item, const std::shared_ptr& videoVersion) - : m_item{item}, m_videoVersion{videoVersion} + : CVideoPlayActionProcessorBase(item, videoVersion) { } - virtual ~CVideoSelectActionProcessorBase() = default; - - static Action GetDefaultSelectAction(); - bool Process(); - bool Process(Action selectAction); + ~CVideoSelectActionProcessorBase() override = default; - static Action ChoosePlayOrResume(const CFileItem& item); + static Action GetDefaultSelectAction(); protected: + Action GetDefaultAction() override; + bool Process(Action action) override; + virtual bool OnPlayPartSelected(unsigned int part) = 0; - virtual bool OnResumeSelected() = 0; - virtual bool OnPlaySelected() = 0; virtual bool OnQueueSelected() = 0; virtual bool OnInfoSelected() = 0; virtual bool OnMoreSelected() = 0; - std::shared_ptr m_item; - private: CVideoSelectActionProcessorBase() = delete; Action ChooseVideoItemSelectAction() const; unsigned int ChooseStackItemPartNumber() const; - - bool m_versionChecked{false}; - const std::shared_ptr m_videoVersion; }; } // namespace GUILIB } // namespace VIDEO diff --git a/xbmc/video/windows/GUIWindowVideoBase.cpp b/xbmc/video/windows/GUIWindowVideoBase.cpp index 6ad778a048263..99721ed0b8ec5 100644 --- a/xbmc/video/windows/GUIWindowVideoBase.cpp +++ b/xbmc/video/windows/GUIWindowVideoBase.cpp @@ -614,7 +614,7 @@ bool CGUIWindowVideoBase::OnFileAction(int iItem, Action action, const std::stri return false; CVideoSelectActionProcessor proc(*this, item, iItem, player); - return proc.Process(action); + return proc.ProcessAction(action); } bool CGUIWindowVideoBase::OnItemInfo(int iItem) @@ -776,7 +776,7 @@ bool CGUIWindowVideoBase::OnPlayOrResumeItem(int iItem, const std::string& playe return false; CVideoPlayActionProcessor proc{*this, m_vecItems->Get(iItem), iItem, player}; - return proc.Process(); + return proc.ProcessDefaultAction(); } void CGUIWindowVideoBase::GetContextButtons(int itemNumber, CContextButtons &buttons)