[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / dialogs / GUIDialogSimpleMenu.cpp
blobfed153fb16f5af5c6c226a96d6d1dafd9a9f373c
1 /*
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.
7 */
10 #include "GUIDialogSimpleMenu.h"
12 #include "FileItem.h"
13 #include "FileItemList.h"
14 #include "GUIDialogSelect.h"
15 #include "ServiceBroker.h"
16 #include "URL.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"
32 using namespace KODI;
34 namespace
36 class CGetDirectoryItems : public IRunnable
38 public:
39 CGetDirectoryItems(const std::string &path, CFileItemList &items, const XFILE::CDirectory::CHints &hints)
40 : m_path(path), m_items(items), m_hints(hints)
43 void Run() override
45 m_result = XFILE::CDirectory::GetDirectory(m_path, m_items, m_hints);
47 bool m_result;
48 protected:
49 std::string m_path;
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)
58 return true;
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())
81 CURL url2("udf://");
82 url2.SetHostName(item.GetDynPath());
83 url2.SetFileName("BDMV/index.bdmv");
84 if (CFileUtils::Exists(url2.Get()))
86 url2.SetFileName("");
88 CURL url("bluray://");
89 url.SetHostName(url2.Get());
90 url.SetFileName("root");
91 return ShowPlaySelection(item, url.Get());
94 return true;
97 bool CGUIDialogSimpleMenu::ShowPlaySelection(CFileItem& item, const std::string& directory)
100 CFileItemList items;
102 if (!GetDirectoryItems(directory, items, XFILE::CDirectory::CHints()))
104 CLog::Log(LOGERROR,
105 "CGUIWindowVideoBase::ShowPlaySelection - Failed to get play directory for {}",
106 directory);
107 return true;
110 if (items.IsEmpty())
112 CLog::Log(LOGERROR, "CGUIWindowVideoBase::ShowPlaySelection - Failed to get any items {}",
113 directory);
114 return true;
117 CGUIDialogSelect* dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT);
118 while (true)
120 dialog->Reset();
121 dialog->SetHeading(CVariant{25006}); // Select playback item
122 dialog->SetItems(items);
123 dialog->SetUseDetails(true);
124 dialog->Open();
126 CFileItemPtr item_new = dialog->GetSelectedFileItem();
127 if (!item_new || dialog->GetSelectedItem() < 0)
129 CLog::Log(LOGDEBUG, "CGUIWindowVideoBase::ShowPlaySelection - User aborted {}", directory);
130 break;
133 if (item_new->m_bIsFolder == false)
135 std::string path;
136 if (item.HasProperty("save_dyn_path"))
137 path = item.GetProperty("save_dyn_path").asString();
138 else
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);
143 return true;
146 items.Clear();
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());
151 break;
155 return false;
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))
164 return false;
166 return getItems.m_result;