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.
9 #include "GUIDialogPVRRecordingSettings.h"
12 #include "ServiceBroker.h"
13 #include "guilib/GUIMessage.h"
14 #include "guilib/LocalizeStrings.h"
15 #include "messaging/helpers/DialogHelper.h"
16 #include "pvr/PVRManager.h"
17 #include "pvr/addons/PVRClient.h"
18 #include "pvr/recordings/PVRRecording.h"
19 #include "settings/dialogs/GUIDialogSettingsBase.h"
20 #include "settings/lib/Setting.h"
21 #include "utils/StringUtils.h"
22 #include "utils/Variant.h"
23 #include "utils/log.h"
33 using namespace KODI::MESSAGING
;
35 #define SETTING_RECORDING_NAME "recording.name"
36 #define SETTING_RECORDING_PLAYCOUNT "recording.playcount"
37 #define SETTING_RECORDING_LIFETIME "recording.lifetime"
39 CGUIDialogPVRRecordingSettings::CGUIDialogPVRRecordingSettings()
40 : CGUIDialogSettingsManualBase(WINDOW_DIALOG_PVR_RECORDING_SETTING
, "DialogSettings.xml")
42 m_loadType
= LOAD_EVERY_TIME
;
45 void CGUIDialogPVRRecordingSettings::SetRecording(const std::shared_ptr
<CPVRRecording
>& recording
)
49 CLog::LogF(LOGERROR
, "No recording given");
53 m_recording
= recording
;
55 // Copy data we need from tag. Do not modify the tag itself until Save()!
56 m_strTitle
= m_recording
->m_strTitle
;
57 m_iPlayCount
= m_recording
->GetLocalPlayCount();
58 m_iLifetime
= m_recording
->LifeTime();
61 void CGUIDialogPVRRecordingSettings::SetupView()
63 CGUIDialogSettingsManualBase::SetupView();
64 SetHeading(19068); // Recording settings
65 SET_CONTROL_HIDDEN(CONTROL_SETTINGS_CUSTOM_BUTTON
);
66 SET_CONTROL_LABEL(CONTROL_SETTINGS_OKAY_BUTTON
, 186); // OK
67 SET_CONTROL_LABEL(CONTROL_SETTINGS_CANCEL_BUTTON
, 222); // Cancel
70 void CGUIDialogPVRRecordingSettings::InitializeSettings()
72 CGUIDialogSettingsManualBase::InitializeSettings();
74 const std::shared_ptr
<CSettingCategory
> category
= AddCategory("pvrrecordingsettings", -1);
75 if (category
== nullptr)
77 CLog::LogF(LOGERROR
, "Unable to add settings category");
81 const std::shared_ptr
<CSettingGroup
> group
= AddGroup(category
);
84 CLog::LogF(LOGERROR
, "Unable to add settings group");
88 std::shared_ptr
<CSetting
> setting
= nullptr;
89 const std::shared_ptr
<const CPVRClient
> client
=
90 CServiceBroker::GetPVRManager().GetClient(m_recording
->ClientID());
93 setting
= AddEdit(group
, SETTING_RECORDING_NAME
, 19075, SettingLevel::Basic
, m_strTitle
);
94 setting
->SetEnabled(client
&& client
->GetClientCapabilities().SupportsRecordingsRename());
97 if (client
&& client
->GetClientCapabilities().SupportsRecordingsPlayCount())
98 setting
= AddEdit(group
, SETTING_RECORDING_PLAYCOUNT
, 567, SettingLevel::Basic
,
99 m_recording
->GetLocalPlayCount());
102 if (client
&& client
->GetClientCapabilities().SupportsRecordingsLifetimeChange())
103 setting
= AddList(group
, SETTING_RECORDING_LIFETIME
, 19083, SettingLevel::Basic
, m_iLifetime
,
104 LifetimesFiller
, 19083);
107 bool CGUIDialogPVRRecordingSettings::CanEditRecording(const CFileItem
& item
)
109 if (!item
.HasPVRRecordingInfoTag())
112 const std::shared_ptr
<const CPVRClient
> client
=
113 CServiceBroker::GetPVRManager().GetClient(item
.GetPVRRecordingInfoTag()->ClientID());
118 const CPVRClientCapabilities
& capabilities
= client
->GetClientCapabilities();
120 return capabilities
.SupportsRecordingsRename() || capabilities
.SupportsRecordingsPlayCount() ||
121 capabilities
.SupportsRecordingsLifetimeChange();
124 bool CGUIDialogPVRRecordingSettings::OnSettingChanging(
125 const std::shared_ptr
<const CSetting
>& setting
)
127 if (setting
== nullptr)
129 CLog::LogF(LOGERROR
, "No setting");
133 const std::string
& settingId
= setting
->GetId();
135 if (settingId
== SETTING_RECORDING_LIFETIME
)
137 int iNewLifetime
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
138 if (m_recording
->WillBeExpiredWithNewLifetime(iNewLifetime
))
140 if (HELPERS::ShowYesNoDialogText(
141 CVariant
{19068}, // "Recording settings"
142 StringUtils::Format(g_localizeStrings
.Get(19147),
143 iNewLifetime
)) // "Setting the lifetime..."
144 != HELPERS::DialogResponse::CHOICE_YES
)
149 return CGUIDialogSettingsManualBase::OnSettingChanging(setting
);
152 void CGUIDialogPVRRecordingSettings::OnSettingChanged(
153 const std::shared_ptr
<const CSetting
>& setting
)
155 if (setting
== nullptr)
157 CLog::LogF(LOGERROR
, "No setting");
161 CGUIDialogSettingsManualBase::OnSettingChanged(setting
);
163 const std::string
& settingId
= setting
->GetId();
165 if (settingId
== SETTING_RECORDING_NAME
)
167 m_strTitle
= std::static_pointer_cast
<const CSettingString
>(setting
)->GetValue();
169 else if (settingId
== SETTING_RECORDING_PLAYCOUNT
)
171 m_iPlayCount
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
173 else if (settingId
== SETTING_RECORDING_LIFETIME
)
175 m_iLifetime
= std::static_pointer_cast
<const CSettingInt
>(setting
)->GetValue();
179 bool CGUIDialogPVRRecordingSettings::Save()
182 m_recording
->m_strTitle
= m_strTitle
;
185 m_recording
->SetLocalPlayCount(m_iPlayCount
);
188 m_recording
->SetLifeTime(m_iLifetime
);
193 void CGUIDialogPVRRecordingSettings::LifetimesFiller(const SettingConstPtr
& setting
,
194 std::vector
<IntegerSettingOption
>& list
,
198 CGUIDialogPVRRecordingSettings
* pThis
= static_cast<CGUIDialogPVRRecordingSettings
*>(data
);
203 const std::shared_ptr
<const CPVRClient
> client
=
204 CServiceBroker::GetPVRManager().GetClient(pThis
->m_recording
->ClientID());
207 std::vector
<std::pair
<std::string
, int>> values
;
208 client
->GetClientCapabilities().GetRecordingsLifetimeValues(values
);
210 values
.cbegin(), values
.cend(), std::back_inserter(list
),
211 [](const auto& value
) { return IntegerSettingOption(value
.first
, value
.second
); });
214 current
= pThis
->m_iLifetime
;
216 auto it
= list
.begin();
217 while (it
!= list
.end())
219 if (it
->value
== current
)
220 break; // value already in list
225 if (it
== list
.end())
227 // PVR backend supplied value is not in the list of predefined values. Insert it.
228 list
.insert(it
, IntegerSettingOption(
229 StringUtils::Format(g_localizeStrings
.Get(17999), current
) /* {} days */,
234 CLog::LogF(LOGERROR
, "No dialog");