aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorksooo <3226626+ksooo@users.noreply.github.com>2023-12-05 18:53:12 +0100
committerksooo <3226626+ksooo@users.noreply.github.com>2023-12-07 19:08:40 +0100
commitc8b8c2f3cbf4758fdc254c5b0802e9e2a920109c (patch)
treea49cae43c1aa8356098e36c7a532a901e3081999
parent37275b58d7410104081fcb2cb1431826a07083d5 (diff)
[video] Add context menu item 'Choose version' for videos with multiple versions.
-rw-r--r--addons/resource.language.en_gb/resources/strings.po8
-rw-r--r--xbmc/ContextMenuManager.cpp1
-rw-r--r--xbmc/video/ContextMenus.cpp82
-rw-r--r--xbmc/video/ContextMenus.h7
-rw-r--r--xbmc/video/guilib/VideoActionProcessorHelper.cpp64
5 files changed, 132 insertions, 30 deletions
diff --git a/addons/resource.language.en_gb/resources/strings.po b/addons/resource.language.en_gb/resources/strings.po
index fe7d42af8f..296c4039e1 100644
--- a/addons/resource.language.en_gb/resources/strings.po
+++ b/addons/resource.language.en_gb/resources/strings.po
@@ -23922,6 +23922,14 @@ msgctxt "#40207"
msgid "When enabled, a video with multiple versions will be shown as a folder in the video library. This folder can then be opened to display the individual video versions. When disabled, the configured select action will be applied."
msgstr ""
+#. Choose video version context menu item label
+#: xbmc/video/ContextMenus.h
+msgctxt "#40208"
+msgid "Choose version"
+msgstr ""
+
+#empty strings from id 40209 to 40399
+
# Video versions
#. Name of a video version, like "Director's Cut"
diff --git a/xbmc/ContextMenuManager.cpp b/xbmc/ContextMenuManager.cpp
index 607e960366..7aed939162 100644
--- a/xbmc/ContextMenuManager.cpp
+++ b/xbmc/ContextMenuManager.cpp
@@ -62,6 +62,7 @@ void CContextMenuManager::Init()
std::unique_lock<CCriticalSection> lock(m_criticalSection);
m_items = {
std::make_shared<CONTEXTMENU::CVideoBrowse>(),
+ std::make_shared<CONTEXTMENU::CVideoChooseVersion>(),
std::make_shared<CONTEXTMENU::CVideoResume>(),
std::make_shared<CONTEXTMENU::CVideoPlay>(),
std::make_shared<CONTEXTMENU::CVideoPlayUsing>(),
diff --git a/xbmc/video/ContextMenus.cpp b/xbmc/video/ContextMenus.cpp
index ec7a1bbd3f..4128284579 100644
--- a/xbmc/video/ContextMenus.cpp
+++ b/xbmc/video/ContextMenus.cpp
@@ -9,6 +9,7 @@
#include "ContextMenus.h"
#include "Autorun.h"
+#include "ContextMenuManager.h"
#include "FileItem.h"
#include "GUIUserMessages.h"
#include "ServiceBroker.h"
@@ -17,11 +18,14 @@
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/LocalizeStrings.h"
+#include "utils/ExecString.h"
+#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
#include "video/VideoInfoTag.h"
#include "video/VideoUtils.h"
#include "video/dialogs/GUIDialogVideoInfo.h"
#include "video/guilib/VideoPlayActionProcessor.h"
+#include "video/guilib/VideoSelectActionProcessor.h"
#include <utility>
@@ -159,6 +163,84 @@ bool CVideoBrowse::Execute(const std::shared_ptr<CFileItem>& item) const
return true;
}
+namespace
+{
+bool ExecuteAction(const CExecString& execute)
+{
+ const std::string execStr{execute.GetExecString()};
+ if (!execStr.empty())
+ {
+ CGUIMessage message(GUI_MSG_EXECUTE, 0, 0);
+ message.SetStringParam(execStr);
+ CServiceBroker::GetGUI()->GetWindowManager().SendMessage(message);
+ return true;
+ }
+ return false;
+}
+
+class CVideoSelectActionProcessor : public VIDEO::GUILIB::CVideoSelectActionProcessorBase
+{
+public:
+ explicit CVideoSelectActionProcessor(const std::shared_ptr<CFileItem>& item)
+ : CVideoSelectActionProcessorBase(item)
+ {
+ }
+
+protected:
+ bool OnPlayPartSelected(unsigned int part) override
+ {
+ // part numbers are 1-based
+ ExecuteAction({"PlayMedia", *m_item, StringUtils::Format("playoffset={}", part - 1)});
+ return true;
+ }
+
+ bool OnResumeSelected() override
+ {
+ ExecuteAction({"PlayMedia", *m_item, "resume"});
+ return true;
+ }
+
+ bool OnPlaySelected() override
+ {
+ ExecuteAction({"PlayMedia", *m_item, "noresume"});
+ return true;
+ }
+
+ bool OnQueueSelected() override
+ {
+ ExecuteAction({"QueueMedia", *m_item, ""});
+ return true;
+ }
+
+ bool OnInfoSelected() override
+ {
+ CGUIDialogVideoInfo::ShowFor(*m_item);
+ return true;
+ }
+
+ bool OnMoreSelected() override
+ {
+ CONTEXTMENU::ShowFor(m_item, CContextMenuManager::MAIN);
+ return true;
+ }
+};
+} // unnamed namespace
+
+bool CVideoChooseVersion::IsVisible(const CFileItem& item) const
+{
+ return item.HasVideoVersions();
+}
+
+bool CVideoChooseVersion::Execute(const std::shared_ptr<CFileItem>& 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();
+ item->ClearProperty("force_choose_video_version");
+ return ret;
+}
+
std::string CVideoResume::GetLabel(const CFileItem& item) const
{
return VIDEO_UTILS::GetResumeString(item.GetItemToPlay());
diff --git a/xbmc/video/ContextMenus.h b/xbmc/video/ContextMenus.h
index e220670b02..6728f58d54 100644
--- a/xbmc/video/ContextMenus.h
+++ b/xbmc/video/ContextMenus.h
@@ -86,6 +86,13 @@ struct CVideoBrowse : CStaticContextMenuAction
bool Execute(const std::shared_ptr<CFileItem>& item) const override;
};
+struct CVideoChooseVersion : CStaticContextMenuAction
+{
+ CVideoChooseVersion() : CStaticContextMenuAction(40208) {} // Choose version
+ bool IsVisible(const CFileItem& item) const override;
+ bool Execute(const std::shared_ptr<CFileItem>& item) const override;
+};
+
struct CVideoResume : IContextMenuItem
{
std::string GetLabel(const CFileItem& item) const override;
diff --git a/xbmc/video/guilib/VideoActionProcessorHelper.cpp b/xbmc/video/guilib/VideoActionProcessorHelper.cpp
index 405f7a298f..04f3132cbb 100644
--- a/xbmc/video/guilib/VideoActionProcessorHelper.cpp
+++ b/xbmc/video/guilib/VideoActionProcessorHelper.cpp
@@ -99,48 +99,52 @@ std::shared_ptr<CFileItem> CVideoActionProcessorHelper::ChooseVideoVersion()
{
if (!m_videoVersion && m_item->HasVideoVersions())
{
- // select the specified video version
- if (m_item->GetVideoInfoTag()->m_idVideoVersion > 0)
- m_videoVersion = m_item;
+ if (!m_item->GetProperty("force_choose_video_version").asBoolean(false))
+ {
+ // select the specified video version
+ if (m_item->GetVideoInfoTag()->m_idVideoVersion > 0)
+ m_videoVersion = m_item;
- const auto settings{CServiceBroker::GetSettingsComponent()->GetSettings()};
+ const auto settings{CServiceBroker::GetSettingsComponent()->GetSettings()};
- if (!m_videoVersion)
- {
- //! @todo get rid of this hack to patch away item's folder flag if it is video version
- //! folder
- if (m_item->GetVideoInfoTag()->m_idVideoVersion == VIDEO_VERSION_ID_ALL &&
- settings->GetBool(CSettings::SETTING_VIDEOLIBRARY_SHOWVIDEOVERSIONSASFOLDER))
+ if (!m_videoVersion)
{
- m_item->m_bIsFolder = false;
- m_restoreFolderFlag = true;
+ //! @todo get rid of this hack to patch away item's folder flag if it is video version
+ //! folder
+ if (m_item->GetVideoInfoTag()->m_idVideoVersion == VIDEO_VERSION_ID_ALL &&
+ settings->GetBool(CSettings::SETTING_VIDEOLIBRARY_SHOWVIDEOVERSIONSASFOLDER))
+ {
+ m_item->m_bIsFolder = false;
+ m_restoreFolderFlag = true;
+ }
}
- }
- if (!m_videoVersion)
- {
- // select the default video version
- if (settings->GetBool(CSettings::SETTING_MYVIDEOS_SELECTDEFAULTVERSION))
+ if (!m_videoVersion)
{
- CVideoDatabase db;
- if (!db.Open())
- {
- CLog::LogF(LOGERROR, "Unable to open video database!");
- }
- else
+ // select the default video version
+ if (settings->GetBool(CSettings::SETTING_MYVIDEOS_SELECTDEFAULTVERSION))
{
- CFileItem defaultVersion;
- db.GetDefaultVideoVersion(m_item->GetVideoContentType(),
- m_item->GetVideoInfoTag()->m_iDbId, defaultVersion);
- if (!defaultVersion.HasVideoInfoTag() || defaultVersion.GetVideoInfoTag()->IsEmpty())
- CLog::LogF(LOGERROR, "Unable to get default video version from video database!");
+ CVideoDatabase db;
+ if (!db.Open())
+ {
+ CLog::LogF(LOGERROR, "Unable to open video database!");
+ }
else
- m_videoVersion = std::make_shared<const CFileItem>(defaultVersion);
+ {
+ CFileItem defaultVersion;
+ db.GetDefaultVideoVersion(m_item->GetVideoContentType(),
+ m_item->GetVideoInfoTag()->m_iDbId, defaultVersion);
+ if (!defaultVersion.HasVideoInfoTag() || defaultVersion.GetVideoInfoTag()->IsEmpty())
+ CLog::LogF(LOGERROR, "Unable to get default video version from video database!");
+ else
+ m_videoVersion = std::make_shared<const CFileItem>(defaultVersion);
+ }
}
}
}
- if (!m_videoVersion && !m_item->GetProperty("prohibit_choose_video_version").asBoolean(false))
+ if (!m_videoVersion && (m_item->GetProperty("force_choose_video_version").asBoolean(false) ||
+ !m_item->GetProperty("prohibit_choose_video_version").asBoolean(false)))
{
const auto result{CGUIDialogVideoVersion::ChooseVideoVersion(m_item)};
if (result.cancelled)