[video] fix selection after changing video or extra art
[xbmc.git] / xbmc / pvr / guilib / PVRGUIActionsClients.cpp
blobb9c598c7944ef7b657d82f0609512c1b13003cf8
1 /*
2 * Copyright (C) 2016-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 */
9 #include "PVRGUIActionsClients.h"
11 #include "ServiceBroker.h"
12 #include "dialogs/GUIDialogSelect.h"
13 #include "guilib/GUIComponent.h"
14 #include "guilib/GUIWindowManager.h"
15 #include "guilib/WindowIDs.h"
16 #include "messaging/helpers/DialogOKHelper.h"
17 #include "pvr/PVRManager.h"
18 #include "pvr/addons/PVRClient.h"
19 #include "pvr/addons/PVRClientMenuHooks.h"
20 #include "pvr/addons/PVRClients.h"
21 #include "utils/Variant.h"
22 #include "utils/log.h"
24 #include <algorithm>
25 #include <iterator>
26 #include <memory>
27 #include <utility>
28 #include <vector>
30 using namespace KODI::MESSAGING;
32 using namespace PVR;
34 bool CPVRGUIActionsClients::ProcessSettingsMenuHooks()
36 const CPVRClientMap clients = CServiceBroker::GetPVRManager().Clients()->GetCreatedClients();
38 std::vector<std::pair<std::shared_ptr<CPVRClient>, CPVRClientMenuHook>> settingsHooks;
39 for (const auto& client : clients)
41 const auto hooks = client.second->GetMenuHooks()->GetSettingsHooks();
42 std::transform(hooks.cbegin(), hooks.cend(), std::back_inserter(settingsHooks),
43 [&client](const auto& hook) { return std::make_pair(client.second, hook); });
46 if (settingsHooks.empty())
48 HELPERS::ShowOKDialogText(
49 CVariant{19033}, // "Information"
50 CVariant{19347}); // "None of the active PVR clients does provide client-specific settings."
51 return true; // no settings hooks, no error
54 auto selectedHook = settingsHooks.begin();
56 // if there is only one settings hook, execute it directly, otherwise let the user select
57 if (settingsHooks.size() > 1)
59 CGUIDialogSelect* pDialog =
60 CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>(
61 WINDOW_DIALOG_SELECT);
62 if (!pDialog)
64 CLog::LogF(LOGERROR, "Unable to get WINDOW_DIALOG_SELECT!");
65 return false;
68 pDialog->Reset();
69 pDialog->SetHeading(CVariant{19196}); // "PVR client specific actions"
71 for (const auto& hook : settingsHooks)
73 if (clients.size() == 1)
74 pDialog->Add(hook.second.GetLabel());
75 else
76 pDialog->Add(hook.first->GetFriendlyName() + ": " + hook.second.GetLabel());
79 pDialog->Open();
81 int selection = pDialog->GetSelectedItem();
82 if (selection < 0)
83 return true; // cancelled
85 std::advance(selectedHook, selection);
87 return selectedHook->first->CallSettingsMenuHook(selectedHook->second) == PVR_ERROR_NO_ERROR;