Skip to content

Commit

Permalink
[favourites] CGUIWindowFavourites: Add support for default play actio…
Browse files Browse the repository at this point in the history
…n setting.
  • Loading branch information
ksooo committed Oct 4, 2023
1 parent e44db7f commit 6e437c7
Showing 1 changed file with 49 additions and 26 deletions.
75 changes: 49 additions & 26 deletions xbmc/favourites/GUIWindowFavourites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "utils/StringUtils.h"
#include "video/VideoUtils.h"
#include "video/dialogs/GUIDialogVideoInfo.h"
#include "video/guilib/VideoPlayActionProcessor.h"
#include "video/guilib/VideoSelectActionProcessor.h"

CGUIWindowFavourites::CGUIWindowFavourites()
Expand Down Expand Up @@ -117,6 +118,25 @@ class CVideoSelectActionProcessor : public VIDEO::GUILIB::CVideoSelectActionProc
return true;
}
};

class CVideoPlayActionProcessor : public VIDEO::GUILIB::CVideoPlayActionProcessorBase
{
public:
explicit CVideoPlayActionProcessor(CFileItem& item) : CVideoPlayActionProcessorBase(item) {}

protected:
bool OnResumeSelected() override
{
ExecuteAction({"PlayMedia", m_item, "resume"});
return true;
}

bool OnPlaySelected() override
{
ExecuteAction({"PlayMedia", m_item, "noresume"});
return true;
}
};
} // namespace

bool CGUIWindowFavourites::OnSelect(int item)
Expand All @@ -128,19 +148,21 @@ bool CGUIWindowFavourites::OnSelect(int item)
if (!favURL.IsValid())
return false;

if (favURL.GetAction() == CFavouritesURL::Action::PLAY_MEDIA)
CFileItem targetItem{favURL.GetTarget(), favURL.IsDir()};
targetItem.LoadDetails();

const bool isNoFolderOrIsPlayMedia{!targetItem.m_bIsFolder ||
(favURL.GetAction() == CFavouritesURL::Action::PLAY_MEDIA)};

// video select action setting is for files only, except exec func is playmedia...
if (isNoFolderOrIsPlayMedia && targetItem.HasVideoInfoTag())
{
// Resolve the favourite
CFileItem targetItem{favURL.GetTarget(), favURL.IsDir()};
targetItem.LoadDetails();
if (targetItem.IsVideo() || (targetItem.m_bIsFolder && VIDEO_UTILS::IsItemPlayable(targetItem)))
{
CVideoSelectActionProcessor proc{targetItem};
if (proc.Process())
return true;
}
CVideoSelectActionProcessor proc{targetItem};
if (proc.Process())
return true;
}

// exec the execute string for the original (!) item
return ExecuteAction(favURL.GetExecString());
}

Expand All @@ -156,26 +178,27 @@ bool CGUIWindowFavourites::OnAction(const CAction& action)
if (!favURL.IsValid())
return false;

// If action is playmedia, just play it
if (favURL.GetAction() == CFavouritesURL::Action::PLAY_MEDIA)
return ExecuteAction(favURL.GetExecString());
CFileItem item{favURL.GetTarget(), favURL.IsDir()};
item.LoadDetails();

// Resolve and check the target
const auto item = std::make_shared<CFileItem>(favURL.GetTarget(), favURL.IsDir());
if (CPlayerUtils::IsItemPlayable(*item))
// video play action setting is for files and folders...
if (item.HasVideoInfoTag() || (item.m_bIsFolder && VIDEO_UTILS::IsItemPlayable(item)))
{
CFavouritesURL target(*item, {});
if (target.GetAction() == CFavouritesURL::Action::PLAY_MEDIA)
{
return ExecuteAction(target.GetExecString());
}
else
CVideoPlayActionProcessor proc{item};
if (proc.Process())
return true;
}

if (CPlayerUtils::IsItemPlayable(item))
{
CFavouritesURL target{item, {}};
if (target.GetAction() != CFavouritesURL::Action::PLAY_MEDIA)
{
// build and execute a playmedia execute string
target = CFavouritesURL(CFavouritesURL::Action::PLAY_MEDIA,
{StringUtils::Paramify(item->GetPath())});
return ExecuteAction(target.GetExecString());
// build a playmedia execute string for given target
target = CFavouritesURL{CFavouritesURL::Action::PLAY_MEDIA,
{StringUtils::Paramify(item.GetPath())}};
}
return ExecuteAction(target.GetExecString());
}
return false;
}
Expand Down

0 comments on commit 6e437c7

Please sign in to comment.