2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
10 #include "GUIDialogSimpleMenu.h"
13 #include "FileItemList.h"
14 #include "GUIDialogSelect.h"
15 #include "ServiceBroker.h"
17 #include "dialogs/GUIDialogBusy.h"
18 #include "filesystem/Directory.h"
19 #include "guilib/GUIComponent.h"
20 #include "guilib/GUIWindowManager.h"
21 #include "settings/DiscSettings.h"
22 #include "settings/Settings.h"
23 #include "settings/SettingsComponent.h"
24 #include "threads/IRunnable.h"
25 #include "utils/FileUtils.h"
26 #include "utils/URIUtils.h"
27 #include "utils/Variant.h"
28 #include "utils/log.h"
29 #include "video/VideoFileItemClassify.h"
30 #include "video/VideoInfoTag.h"
36 class CGetDirectoryItems
: public IRunnable
39 CGetDirectoryItems(const std::string
&path
, CFileItemList
&items
, const XFILE::CDirectory::CHints
&hints
)
40 : m_path(path
), m_items(items
), m_hints(hints
)
45 m_result
= XFILE::CDirectory::GetDirectory(m_path
, m_items
, m_hints
);
50 CFileItemList
&m_items
;
51 XFILE::CDirectory::CHints m_hints
;
55 bool CGUIDialogSimpleMenu::ShowPlaySelection(CFileItem
& item
, bool forceSelection
/* = false */)
57 if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_DISC_PLAYBACK
) != BD_PLAYBACK_SIMPLE_MENU
)
60 if (forceSelection
&& VIDEO::IsBlurayPlaylist(item
))
62 item
.SetProperty("save_dyn_path", item
.GetDynPath()); // save for screen refresh later
63 item
.SetDynPath(item
.GetBlurayPath());
66 if (VIDEO::IsBDFile(item
))
68 std::string root
= URIUtils::GetParentPath(item
.GetDynPath());
69 URIUtils::RemoveSlashAtEnd(root
);
70 if (URIUtils::GetFileName(root
) == "BDMV")
72 CURL
url("bluray://");
73 url
.SetHostName(URIUtils::GetParentPath(root
));
74 url
.SetFileName("root");
75 return ShowPlaySelection(item
, url
.Get());
79 if (item
.IsDiscImage())
82 url2
.SetHostName(item
.GetDynPath());
83 url2
.SetFileName("BDMV/index.bdmv");
84 if (CFileUtils::Exists(url2
.Get()))
88 CURL
url("bluray://");
89 url
.SetHostName(url2
.Get());
90 url
.SetFileName("root");
91 return ShowPlaySelection(item
, url
.Get());
97 bool CGUIDialogSimpleMenu::ShowPlaySelection(CFileItem
& item
, const std::string
& directory
)
102 if (!GetDirectoryItems(directory
, items
, XFILE::CDirectory::CHints()))
105 "CGUIWindowVideoBase::ShowPlaySelection - Failed to get play directory for {}",
112 CLog::Log(LOGERROR
, "CGUIWindowVideoBase::ShowPlaySelection - Failed to get any items {}",
117 CGUIDialogSelect
* dialog
= CServiceBroker::GetGUI()->GetWindowManager().GetWindow
<CGUIDialogSelect
>(WINDOW_DIALOG_SELECT
);
121 dialog
->SetHeading(CVariant
{25006}); // Select playback item
122 dialog
->SetItems(items
);
123 dialog
->SetUseDetails(true);
126 CFileItemPtr item_new
= dialog
->GetSelectedFileItem();
127 if (!item_new
|| dialog
->GetSelectedItem() < 0)
129 CLog::Log(LOGDEBUG
, "CGUIWindowVideoBase::ShowPlaySelection - User aborted {}", directory
);
133 if (item_new
->m_bIsFolder
== false)
136 if (item
.HasProperty("save_dyn_path"))
137 path
= item
.GetProperty("save_dyn_path").asString();
139 path
= item
.GetDynPath(); // If not set above (choose playlist selected)
140 item
.SetDynPath(item_new
->GetDynPath());
141 item
.SetProperty("get_stream_details_from_player", true);
142 item
.SetProperty("original_listitem_url", path
);
147 if (!GetDirectoryItems(item_new
->GetDynPath(), items
, XFILE::CDirectory::CHints()) || items
.IsEmpty())
149 CLog::Log(LOGERROR
, "CGUIWindowVideoBase::ShowPlaySelection - Failed to get any items {}",
150 item_new
->GetPath());
158 bool CGUIDialogSimpleMenu::GetDirectoryItems(const std::string
&path
, CFileItemList
&items
,
159 const XFILE::CDirectory::CHints
&hints
)
161 CGetDirectoryItems
getItems(path
, items
, hints
);
162 if (!CGUIDialogBusy::Wait(&getItems
, 100, true))
166 return getItems
.m_result
;