Skip to content

Commit

Permalink
Merge pull request xbmc#24204 from ksooo/video-refactor-action-proces…
Browse files Browse the repository at this point in the history
…sors

[video] Refactor Video Action Processors
  • Loading branch information
ksooo authored Dec 8, 2023
2 parents 38b7bce + 06418a1 commit 5e70594
Show file tree
Hide file tree
Showing 20 changed files with 140 additions and 209 deletions.
4 changes: 2 additions & 2 deletions xbmc/favourites/GUIWindowFavourites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ bool CGUIWindowFavourites::OnSelect(int itemIdx)
if (targetItem.HasVideoInfoTag() && (!targetItem.m_bIsFolder || isPlayMedia))
{
CVideoSelectActionProcessor proc{std::make_shared<CFileItem>(targetItem)};
if (proc.Process())
if (proc.ProcessDefaultAction())
return true;
}

Expand All @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions xbmc/interfaces/builtins/PlayerBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,13 +513,13 @@ int PlayOrQueueMedia(const std::vector<std::string>& 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;
Expand Down
4 changes: 2 additions & 2 deletions xbmc/listproviders/DirectoryProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ bool CDirectoryProvider::OnClick(const CGUIListItemPtr& item)
if (targetItem.HasVideoInfoTag() && (!targetItem.m_bIsFolder || isPlayMedia))
{
CVideoSelectActionProcessor proc{*this, std::make_shared<CFileItem>(targetItem)};
if (proc.Process())
if (proc.ProcessDefaultAction())
return true;
}

Expand Down Expand Up @@ -595,7 +595,7 @@ bool CDirectoryProvider::OnPlay(const CGUIListItemPtr& item)
(targetItem.m_bIsFolder && VIDEO_UTILS::IsItemPlayable(targetItem)))
{
CVideoPlayActionProcessor proc{std::make_shared<CFileItem>(targetItem)};
if (proc.Process())
if (proc.ProcessDefaultAction())
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool CGUIDialogPVRGuideInfo::OnClickButtonPlay(const CGUIMessage& message)
if (recording)
{
CGUIPVRRecordingsPlayActionProcessor proc{std::make_shared<CFileItem>(recording)};
proc.Process();
proc.ProcessDefaultAction();
if (proc.UserCancelled())
Open();
}
Expand Down
2 changes: 1 addition & 1 deletion xbmc/pvr/dialogs/GUIDialogPVRRecordingInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions xbmc/pvr/guilib/PVRGUIActionsPlayback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CFileItem*>(&item)->SetStartOffset(STARTOFFSET_RESUME);
}
else if (action == VIDEO::GUILIB::SELECT_ACTION_PLAY)
else if (action == VIDEO::GUILIB::ACTION_PLAY_FROM_BEGINNING)
{
const_cast<CFileItem*>(&item)->SetStartOffset(0);
}
Expand Down
4 changes: 2 additions & 2 deletions xbmc/pvr/windows/GUIWindowPVRRecordings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -361,7 +361,7 @@ bool CGUIWindowPVRRecordingsBase::OnMessage(CGUIMessage& message)
else
{
CVideoSelectActionProcessor proc(*this, item, iItem);
bReturn = proc.Process();
bReturn = proc.ProcessDefaultAction();
}
break;
}
Expand Down
6 changes: 3 additions & 3 deletions xbmc/video/ContextMenus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ 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();
const bool ret = proc.ProcessDefaultAction();
item->ClearProperty("force_choose_video_version");
return ret;
}
Expand Down Expand Up @@ -315,9 +315,9 @@ void SetPathAndPlay(const std::shared_ptr<CFileItem>& 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.ProcessAction(VIDEO::GUILIB::ACTION_RESUME);
else
proc.Process(VIDEO::GUILIB::PLAY_ACTION_PLAY_FROM_BEGINNING);
proc.ProcessAction(VIDEO::GUILIB::ACTION_PLAY_FROM_BEGINNING);

item->ClearProperty("prohibit_choose_video_version");
}
Expand Down
9 changes: 4 additions & 5 deletions xbmc/video/dialogs/GUIDialogVideoInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<CFileItem>& item)
Expand Down Expand Up @@ -791,21 +790,21 @@ void CGUIDialogVideoInfo::Play(bool resume)
if (resume)
{
CVideoPlayActionProcessor proc{m_movieItem};
proc.Process(PLAY_ACTION_RESUME);
proc.ProcessAction(VIDEO::GUILIB::ACTION_RESUME);
}
else
{
if (GetControl(CONTROL_BTN_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.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
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/dialogs/GUIDialogVideoVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void CGUIDialogVideoVersion::Play()
CloseAll();

CVideoPlayActionProcessor proc{m_videoItem, m_selectedVideoVersion};
proc.Process();
proc.ProcessDefaultAction();
}

void CGUIDialogVideoVersion::Remove()
Expand Down
3 changes: 1 addition & 2 deletions xbmc/video/guilib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
29 changes: 29 additions & 0 deletions xbmc/video/guilib/VideoAction.h
Original file line number Diff line number Diff line change
@@ -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
24 changes: 0 additions & 24 deletions xbmc/video/guilib/VideoPlayAction.h

This file was deleted.

58 changes: 29 additions & 29 deletions xbmc/video/guilib/VideoPlayActionProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,54 @@

using namespace VIDEO::GUILIB;

PlayAction CVideoPlayActionProcessorBase::GetDefaultPlayAction()
Action CVideoPlayActionProcessorBase::GetDefaultAction()
{
return static_cast<PlayAction>(CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(
return static_cast<Action>(CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(
CSettings::SETTING_MYVIDEOS_PLAYACTION));
}

bool CVideoPlayActionProcessorBase::Process()
bool CVideoPlayActionProcessorBase::ProcessDefaultAction()
{
return Process(GetDefaultPlayAction());
return ProcessAction(GetDefaultAction());
}

bool CVideoPlayActionProcessorBase::Process(PlayAction 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 PLAY_ACTION_PLAY_OR_RESUME:
case ACTION_PLAY_OR_RESUME:
{
const VIDEO::GUILIB::PlayAction 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 PLAY_ACTION_RESUME:
case ACTION_RESUME:
return OnResumeSelected();

case PLAY_ACTION_PLAY_FROM_BEGINNING:
case ACTION_PLAY_FROM_BEGINNING:
return OnPlaySelected();

default:
Expand All @@ -76,19 +76,19 @@ bool CVideoPlayActionProcessorBase::Process(PlayAction playAction)
return false; // We did not handle the action.
}

PlayAction CVideoPlayActionProcessorBase::ChoosePlayOrResume()
Action CVideoPlayActionProcessorBase::ChoosePlayOrResume(const CFileItem& item)
{
PlayAction action = PLAY_ACTION_PLAY_FROM_BEGINNING;
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;

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<PlayAction>(CGUIDialogContextMenu::ShowAndGetChoice(choices));
action = static_cast<Action>(CGUIDialogContextMenu::ShowAndGetChoice(choices));
}

return action;
Expand Down
15 changes: 8 additions & 7 deletions xbmc/video/guilib/VideoPlayActionProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#pragma once

#include "video/guilib/VideoPlayAction.h"
#include "video/guilib/VideoAction.h"

#include <memory>

Expand All @@ -29,14 +29,17 @@ class CVideoPlayActionProcessorBase
}
virtual ~CVideoPlayActionProcessorBase() = default;

static PlayAction GetDefaultPlayAction();

bool Process();
bool Process(PlayAction 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;

Expand All @@ -45,9 +48,7 @@ class CVideoPlayActionProcessorBase

private:
CVideoPlayActionProcessorBase() = delete;
PlayAction ChoosePlayOrResume();

bool m_versionChecked{false};
const std::shared_ptr<const CFileItem> m_videoVersion;
};
} // namespace GUILIB
Expand Down
Loading

0 comments on commit 5e70594

Please sign in to comment.