[video] fix selection after changing video or extra art
[xbmc.git] / xbmc / pvr / dialogs / GUIDialogPVRClientPriorities.cpp
blobca83ba129834453647071b52033d15c4dd6e802f
1 /*
2 * Copyright (C) 2017-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 "GUIDialogPVRClientPriorities.h"
11 #include "ServiceBroker.h"
12 #include "guilib/GUIMessage.h"
13 #include "pvr/PVRManager.h"
14 #include "pvr/addons/PVRClient.h"
15 #include "settings/lib/Setting.h"
16 #include "utils/StringUtils.h"
17 #include "utils/log.h"
19 #include <cstdlib>
20 #include <memory>
22 using namespace PVR;
24 CGUIDialogPVRClientPriorities::CGUIDialogPVRClientPriorities() :
25 CGUIDialogSettingsManualBase(WINDOW_DIALOG_PVR_CLIENT_PRIORITIES, "DialogSettings.xml")
27 m_loadType = LOAD_EVERY_TIME;
30 void CGUIDialogPVRClientPriorities::SetupView()
32 CGUIDialogSettingsManualBase::SetupView();
34 SetHeading(19240); // Client priorities
35 SET_CONTROL_HIDDEN(CONTROL_SETTINGS_CUSTOM_BUTTON);
36 SET_CONTROL_LABEL(CONTROL_SETTINGS_OKAY_BUTTON, 186); // OK
37 SET_CONTROL_LABEL(CONTROL_SETTINGS_CANCEL_BUTTON, 222); // Cancel
40 std::string CGUIDialogPVRClientPriorities::GetSettingsLabel(
41 const std::shared_ptr<ISetting>& pSetting)
43 int iClientId = std::atoi(pSetting->GetId().c_str());
44 auto clientEntry = m_clients.find(iClientId);
45 if (clientEntry != m_clients.end())
46 return clientEntry->second->GetFriendlyName();
48 CLog::LogF(LOGERROR, "Unable to obtain pvr client with id '{}'", iClientId);
49 return CGUIDialogSettingsManualBase::GetLocalizedString(13205); // Unknown
52 void CGUIDialogPVRClientPriorities::InitializeSettings()
54 CGUIDialogSettingsManualBase::InitializeSettings();
56 const std::shared_ptr<CSettingCategory> category = AddCategory("pvrclientpriorities", -1);
57 if (category == nullptr)
59 CLog::LogF(LOGERROR, "Unable to add settings category");
60 return;
63 const std::shared_ptr<CSettingGroup> group = AddGroup(category);
64 if (group == nullptr)
66 CLog::LogF(LOGERROR, "Unable to add settings group");
67 return;
70 m_clients = CServiceBroker::GetPVRManager().Clients()->GetCreatedClients();
71 for (const auto& client : m_clients)
73 AddEdit(group, std::to_string(client.second->GetID()), 13205 /* Unknown */, SettingLevel::Basic,
74 client.second->GetPriority());
78 void CGUIDialogPVRClientPriorities::OnSettingChanged(const std::shared_ptr<const CSetting>& setting)
80 if (setting == nullptr)
82 CLog::LogF(LOGERROR, "No setting");
83 return;
86 CGUIDialogSettingsManualBase::OnSettingChanged(setting);
88 m_changedValues[setting->GetId()] = std::static_pointer_cast<const CSettingInt>(setting)->GetValue();
91 bool CGUIDialogPVRClientPriorities::Save()
93 for (const auto& changedClient : m_changedValues)
95 int iClientId = std::atoi(changedClient.first.c_str());
96 auto clientEntry = m_clients.find(iClientId);
97 if (clientEntry != m_clients.end())
98 clientEntry->second->SetPriority(changedClient.second);
101 return true;