| 1 | /* |
| 2 | * Copyright (C) 2023 Team Kodi |
| 3 | * This file is part of Kodi - https://kodi.tv |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 6 | * See LICENSES/README.md for more information. |
| 7 | */ |
| 8 | |
| 9 | #include "VideoPlayActionProcessor.h" |
| 10 | |
| 11 | #include "FileItem.h" |
| 12 | #include "ServiceBroker.h" |
| 13 | #include "dialogs/GUIDialogContextMenu.h" |
| 14 | #include "guilib/LocalizeStrings.h" |
| 15 | #include "settings/Settings.h" |
| 16 | #include "settings/SettingsComponent.h" |
| 17 | #include "utils/Variant.h" |
| 18 | #include "video/VideoUtils.h" |
| 19 | #include "video/guilib/VideoVersionHelper.h" |
| 20 | |
| 21 | using namespace VIDEO::GUILIB; |
| 22 | |
| 23 | Action CVideoPlayActionProcessorBase::GetDefaultAction() |
| 24 | { |
| 25 | return static_cast<Action>(CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt( |
| 26 | CSettings::SETTING_MYVIDEOS_PLAYACTION)); |
| 27 | } |
| 28 | |
| 29 | bool CVideoPlayActionProcessorBase::ProcessDefaultAction() |
| 30 | { |
| 31 | return ProcessAction(GetDefaultAction()); |
| 32 | } |
| 33 | |
| 34 | bool CVideoPlayActionProcessorBase::ProcessAction(Action action) |
| 35 | { |
| 36 | m_userCancelled = false; |
| 37 | |
| 38 | const auto movie{CVideoVersionHelper::ChooseVideoFromAssets(m_item)}; |
| 39 | if (movie) |
| 40 | m_item = movie; |
| 41 | else |
| 42 | { |
| 43 | m_userCancelled = true; |
| 44 | return true; // User cancelled the select menu. We're done. |
| 45 | } |
| 46 | |
| 47 | return Process(action); |
| 48 | } |
| 49 | |
| 50 | bool CVideoPlayActionProcessorBase::Process(Action action) |
| 51 | { |
| 52 | switch (action) |
| 53 | { |
| 54 | case ACTION_PLAY_OR_RESUME: |
| 55 | { |
| 56 | const Action selectedAction = ChoosePlayOrResume(*m_item); |
| 57 | if (selectedAction < 0) |
| 58 | { |
| 59 | m_userCancelled = true; |
| 60 | return true; // User cancelled the select menu. We're done. |
| 61 | } |
| 62 | |
| 63 | return Process(selectedAction); |
| 64 | } |
| 65 | |
| 66 | case ACTION_RESUME: |
| 67 | return OnResumeSelected(); |
| 68 | |
| 69 | case ACTION_PLAY_FROM_BEGINNING: |
| 70 | return OnPlaySelected(); |
| 71 | |
| 72 | default: |
| 73 | break; |
| 74 | } |
| 75 | return false; // We did not handle the action. |
| 76 | } |
| 77 | |
| 78 | Action CVideoPlayActionProcessorBase::ChoosePlayOrResume(const CFileItem& item) |
| 79 | { |
| 80 | Action action = ACTION_PLAY_FROM_BEGINNING; |
| 81 | |
| 82 | const std::string resumeString = VIDEO_UTILS::GetResumeString(item); |
| 83 | if (!resumeString.empty()) |
| 84 | { |
| 85 | CContextButtons choices; |
| 86 | |
| 87 | choices.Add(ACTION_RESUME, resumeString); |
| 88 | choices.Add(ACTION_PLAY_FROM_BEGINNING, 12021); // Play from beginning |
| 89 | |
| 90 | action = static_cast<Action>(CGUIDialogContextMenu::ShowAndGetChoice(choices)); |
| 91 | } |
| 92 | |
| 93 | return action; |
| 94 | } |