Debian Codegraph @

xbmc/video/guilib/VideoSelectActionProcessor.cpp

raw symbols SCIP
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 "VideoSelectActionProcessor.h"
10
11 #include "FileItem.h"
12 #include "ServiceBroker.h"
13 #include "dialogs/GUIDialogSelect.h"
14 #include "filesystem/Directory.h"
15 #include "guilib/GUIComponent.h"
16 #include "guilib/GUIWindowManager.h"
17 #include "guilib/LocalizeStrings.h"
18 #include "settings/Settings.h"
19 #include "settings/SettingsComponent.h"
20 #include "utils/StringUtils.h"
21 #include "utils/Variant.h"
22 #include "video/VideoUtils.h"
23
24 using namespace VIDEO::GUILIB;
25
26 Action CVideoSelectActionProcessorBase::GetDefaultSelectAction()
27 {
28 return static_cast<Action>(CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(
29 CSettings::SETTING_MYVIDEOS_SELECTACTION));
30 }
31
32 Action CVideoSelectActionProcessorBase::GetDefaultAction()
33 {
34 return GetDefaultSelectAction();
35 }
36
37 bool CVideoSelectActionProcessorBase::Process(Action action)
38 {
39 if (CVideoPlayActionProcessorBase::Process(action))
40 return true;
41
42 switch (action)
43 {
44 case ACTION_CHOOSE:
45 return OnChooseSelected();
46
47 case ACTION_PLAYPART:
48 {
49 const unsigned int part = ChooseStackItemPartNumber();
50 if (part < 1) // part numbers are 1-based
51 return false;
52
53 return OnPlayPartSelected(part);
54 }
55
56 case ACTION_QUEUE:
57 return OnQueueSelected();
58
59 case ACTION_INFO:
60 {
61 if (GetDefaultAction() == ACTION_INFO && !m_item->IsVideoDb() && !m_item->IsPlugin() &&
62 !m_item->IsScript() && !m_item->IsPVR() &&
63 !VIDEO_UTILS::HasItemVideoDbInformation(*m_item))
64 {
65 // for items without info fall back to default play action
66 return Process(CVideoPlayActionProcessorBase::GetDefaultAction());
67 }
68
69 return OnInfoSelected();
70 }
71
72 default:
73 break;
74 }
75 return false; // We did not handle the action.
76 }
77
78 unsigned int CVideoSelectActionProcessorBase::ChooseStackItemPartNumber() const
79 {
80 CFileItemList parts;
81 XFILE::CDirectory::GetDirectory(m_item->GetDynPath(), parts, "", XFILE::DIR_FLAG_DEFAULTS);
82
83 for (int i = 0; i < parts.Size(); ++i)
84 parts[i]->SetLabel(StringUtils::Format(g_localizeStrings.Get(23051), i + 1)); // Part #
85
86 CGUIDialogSelect* dialog =
87 CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>(
88 WINDOW_DIALOG_SELECT);
89
90 dialog->Reset();
91 dialog->SetHeading(CVariant{20324}); // Play part...
92 dialog->SetItems(parts);
93 dialog->Open();
94
95 if (!dialog->IsConfirmed())
96 return 0; // User cancelled the dialog.
97
98 return dialog->GetSelectedItem() + 1; // part numbers are 1-based
99 }