diff options
-rw-r--r-- | addons/resource.language.en_gb/resources/strings.po | 27 | ||||
-rwxr-xr-x | system/settings/settings.xml | 11 | ||||
-rw-r--r-- | xbmc/settings/Settings.h | 1 | ||||
-rw-r--r-- | xbmc/video/guilib/CMakeLists.txt | 7 | ||||
-rw-r--r-- | xbmc/video/guilib/VideoPlayAction.h | 24 | ||||
-rw-r--r-- | xbmc/video/guilib/VideoPlayActionProcessor.cpp | 72 | ||||
-rw-r--r-- | xbmc/video/guilib/VideoPlayActionProcessor.h | 41 |
7 files changed, 179 insertions, 4 deletions
diff --git a/addons/resource.language.en_gb/resources/strings.po b/addons/resource.language.en_gb/resources/strings.po index cb5a0b9cfd..5db113c3fd 100644 --- a/addons/resource.language.en_gb/resources/strings.po +++ b/addons/resource.language.en_gb/resources/strings.po @@ -5725,6 +5725,7 @@ msgstr "" #: xbmc/pvr/PVRGUIActionsPlayback.cpp #: xbmc/video/ContextMenus.cpp #: xbmc/video/guilib/VideoSelectActionProcessor.cpp +#: xbmc/video/guilib/VideoPlayActionProcessor.cpp msgctxt "#12021" msgid "Play from beginning" msgstr "" @@ -15309,7 +15310,25 @@ msgctxt "#22033" msgid "Charset" msgstr "" -#empty strings from id 22034 to 22078 +#empty strings from id 22034 to 22075 + +#. Label for setting to choose the default action for "play" +#: system/settings/settings.xml +msgctxt "#22076" +msgid "Default play action" +msgstr "" + +#. Label for value for default play action setting +#: system/settings/settings.xml +msgctxt "#22077" +msgid "Ask if resumable" +msgstr "" + +#. Label for value for default play action setting +#: system/settings/settings.xml +msgctxt "#22078" +msgid "Resume" +msgstr "" #: system/settings/settings.xml msgctxt "#22079" @@ -19638,7 +19657,11 @@ msgctxt "#36203" msgid "Enables the \"Personal Video Recorder\" (PVR) features. This requires that at least one PVR add-on is installed." msgstr "" -#empty string with id 36204 +#. Description of setting with label #22076 "Default play action" +#: system/settings/settings.xml +msgctxt "#36204" +msgid "Toggle between [Ask if resumable] (default) and [Resume].[CR][Ask if resumable] will ask whether to play from beginning or to resume (if a resume point is present).[CR][Resume] will automatically resume videos from the last position that you were viewing them.[CR]If no resume point is set, playback will automatically start from the beginning." +msgstr "" #: system/settings/settings.xml msgctxt "#36205" diff --git a/system/settings/settings.xml b/system/settings/settings.xml index d9218c470d..7154234eee 100755 --- a/system/settings/settings.xml +++ b/system/settings/settings.xml @@ -1015,6 +1015,17 @@ </constraints> <control type="list" format="string" /> </setting> + <setting id="myvideos.playaction" type="integer" label="22076" help="36204"> + <level>0</level> + <default>1</default> <!-- PLAY_ACTION_PLAY_OR_RESUME --> + <constraints> + <options> + <option label="22077">1</option> <!-- PLAY_ACTION_PLAY_OR_RESUME --> + <option label="22078">2</option> <!-- PLAY_ACTION_RESUME --> + </options> + </constraints> + <control type="list" format="string" /> + </setting> <setting id="myvideos.usetags" type="boolean" label="21343" help="21344"> <level>2</level> <default>false</default> diff --git a/xbmc/settings/Settings.h b/xbmc/settings/Settings.h index 349a153065..8a3dead5bb 100644 --- a/xbmc/settings/Settings.h +++ b/xbmc/settings/Settings.h @@ -131,6 +131,7 @@ public: static constexpr auto SETTING_VIDEOPLAYER_SUPPORTMVC = "videoplayer.supportmvc"; static constexpr auto SETTING_VIDEOPLAYER_CONVERTDOVI = "videoplayer.convertdovi"; static constexpr auto SETTING_MYVIDEOS_SELECTACTION = "myvideos.selectaction"; + static constexpr auto SETTING_MYVIDEOS_PLAYACTION = "myvideos.playaction"; static constexpr auto SETTING_MYVIDEOS_USETAGS = "myvideos.usetags"; static constexpr auto SETTING_MYVIDEOS_EXTRACTFLAGS = "myvideos.extractflags"; static constexpr auto SETTING_MYVIDEOS_EXTRACTCHAPTERTHUMBS = "myvideos.extractchapterthumbs"; diff --git a/xbmc/video/guilib/CMakeLists.txt b/xbmc/video/guilib/CMakeLists.txt index fd16dee4cb..b0a93d5234 100644 --- a/xbmc/video/guilib/CMakeLists.txt +++ b/xbmc/video/guilib/CMakeLists.txt @@ -1,6 +1,9 @@ -set(SOURCES VideoSelectActionProcessor.cpp) +set(SOURCES VideoPlayActionProcessor.cpp + VideoSelectActionProcessor.cpp) -set(HEADERS VideoSelectAction.h +set(HEADERS VideoPlayAction.h + VideoPlayActionProcessor.h + VideoSelectAction.h VideoSelectActionProcessor.h) core_add_library(video_guilib) diff --git a/xbmc/video/guilib/VideoPlayAction.h b/xbmc/video/guilib/VideoPlayAction.h new file mode 100644 index 0000000000..a566875602 --- /dev/null +++ b/xbmc/video/guilib/VideoPlayAction.h @@ -0,0 +1,24 @@ +/* + * 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 new file mode 100644 index 0000000000..69f4919f3e --- /dev/null +++ b/xbmc/video/guilib/VideoPlayActionProcessor.cpp @@ -0,0 +1,72 @@ +/* + * 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. + */ + +#include "VideoPlayActionProcessor.h" + +#include "ServiceBroker.h" +#include "dialogs/GUIDialogContextMenu.h" +#include "guilib/LocalizeStrings.h" +#include "settings/Settings.h" +#include "settings/SettingsComponent.h" +#include "video/VideoUtils.h" + +using namespace VIDEO::GUILIB; + +PlayAction CVideoPlayActionProcessorBase::GetDefaultPlayAction() +{ + return static_cast<PlayAction>(CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt( + CSettings::SETTING_MYVIDEOS_PLAYACTION)); +} + +bool CVideoPlayActionProcessorBase::Process() +{ + return Process(GetDefaultPlayAction()); +} + +bool CVideoPlayActionProcessorBase::Process(PlayAction PlayAction) +{ + switch (PlayAction) + { + case PLAY_ACTION_PLAY_OR_RESUME: + { + const VIDEO::GUILIB::PlayAction action = ChoosePlayOrResume(); + if (action < 0) + return true; // User cancelled the select menu. We're done. + + return Process(action); + } + + case PLAY_ACTION_RESUME: + return OnResumeSelected(); + + case PLAY_ACTION_PLAY_FROM_BEGINNING: + return OnPlaySelected(); + + default: + break; + } + return false; // We did not handle the action. +} + +PlayAction CVideoPlayActionProcessorBase::ChoosePlayOrResume() +{ + PlayAction action = PLAY_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 + + action = static_cast<PlayAction>(CGUIDialogContextMenu::ShowAndGetChoice(choices)); + } + + return action; +} diff --git a/xbmc/video/guilib/VideoPlayActionProcessor.h b/xbmc/video/guilib/VideoPlayActionProcessor.h new file mode 100644 index 0000000000..9c7076d2f0 --- /dev/null +++ b/xbmc/video/guilib/VideoPlayActionProcessor.h @@ -0,0 +1,41 @@ +/* + * 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 + +#include "video/guilib/VideoPlayAction.h" + +class CFileItem; + +namespace VIDEO +{ +namespace GUILIB +{ +class CVideoPlayActionProcessorBase +{ +public: + explicit CVideoPlayActionProcessorBase(CFileItem& item) : m_item(item) {} + virtual ~CVideoPlayActionProcessorBase() = default; + + static PlayAction GetDefaultPlayAction(); + + bool Process(); + bool Process(PlayAction playAction); + +protected: + virtual bool OnResumeSelected() = 0; + virtual bool OnPlaySelected() = 0; + + CFileItem& m_item; + +private: + CVideoPlayActionProcessorBase() = delete; + PlayAction ChoosePlayOrResume(); +}; +} // namespace GUILIB +} // namespace VIDEO |