[Windows] Fix driver version detection of AMD RDNA+ GPU on Windows 10
[xbmc.git] / xbmc / pvr / guilib / PVRGUIActionsRecordings.cpp
blob9609617be9ac44da874f4ba4c304d725bfb3d340
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 "PVRGUIActionsRecordings.h"
11 #include "FileItem.h"
12 #include "FileItemList.h"
13 #include "ServiceBroker.h"
14 #include "Util.h"
15 #include "dialogs/GUIDialogBusy.h"
16 #include "dialogs/GUIDialogYesNo.h"
17 #include "filesystem/IDirectory.h"
18 #include "guilib/GUIComponent.h"
19 #include "guilib/GUIWindowManager.h"
20 #include "guilib/WindowIDs.h"
21 #include "messaging/helpers/DialogOKHelper.h"
22 #include "pvr/PVRItem.h"
23 #include "pvr/PVRManager.h"
24 #include "pvr/addons/PVRClient.h"
25 #include "pvr/addons/PVRClients.h"
26 #include "pvr/dialogs/GUIDialogPVRRecordingInfo.h"
27 #include "pvr/dialogs/GUIDialogPVRRecordingSettings.h"
28 #include "pvr/recordings/PVRRecording.h"
29 #include "settings/Settings.h"
30 #include "threads/IRunnable.h"
31 #include "utils/Variant.h"
32 #include "utils/log.h"
34 #include <memory>
35 #include <numeric>
36 #include <string>
38 using namespace PVR;
39 using namespace KODI::MESSAGING;
41 namespace
43 class AsyncRecordingAction : private IRunnable
45 public:
46 bool Execute(const CFileItem& item);
48 protected:
49 AsyncRecordingAction() = default;
51 private:
52 // IRunnable implementation
53 void Run() override;
55 // the worker function
56 virtual bool DoRun(const std::shared_ptr<CFileItem>& item) = 0;
58 std::shared_ptr<CFileItem> m_item;
59 bool m_bSuccess = false;
62 bool AsyncRecordingAction::Execute(const CFileItem& item)
64 m_item = std::make_shared<CFileItem>(item);
65 CGUIDialogBusy::Wait(this, 100, false);
66 return m_bSuccess;
69 void AsyncRecordingAction::Run()
71 m_bSuccess = DoRun(m_item);
73 if (m_bSuccess)
74 CServiceBroker::GetPVRManager().TriggerRecordingsUpdate();
77 class AsyncRenameRecording : public AsyncRecordingAction
79 public:
80 explicit AsyncRenameRecording(const std::string& strNewName) : m_strNewName(strNewName) {}
82 private:
83 bool DoRun(const std::shared_ptr<CFileItem>& item) override
85 if (item->IsUsablePVRRecording())
87 return item->GetPVRRecordingInfoTag()->Rename(m_strNewName);
89 else
91 CLog::LogF(LOGERROR, "Cannot rename item '{}': no valid recording tag", item->GetPath());
92 return false;
95 std::string m_strNewName;
98 class AsyncDeleteRecording : public AsyncRecordingAction
100 public:
101 explicit AsyncDeleteRecording(bool bWatchedOnly = false) : m_bWatchedOnly(bWatchedOnly) {}
103 private:
104 bool DoRun(const std::shared_ptr<CFileItem>& item) override
106 CFileItemList items;
107 if (item->m_bIsFolder)
109 CUtil::GetRecursiveListing(item->GetPath(), items, "", XFILE::DIR_FLAG_NO_FILE_INFO);
111 else
113 items.Add(item);
116 return std::accumulate(
117 items.cbegin(), items.cend(), true, [this](bool success, const auto& itemToDelete) {
118 return (itemToDelete->IsPVRRecording() &&
119 (!m_bWatchedOnly || itemToDelete->GetPVRRecordingInfoTag()->GetPlayCount() > 0) &&
120 !itemToDelete->GetPVRRecordingInfoTag()->Delete())
121 ? false
122 : success;
125 bool m_bWatchedOnly = false;
128 class AsyncEmptyRecordingsTrash : public AsyncRecordingAction
130 private:
131 bool DoRun(const std::shared_ptr<CFileItem>& item) override
133 return CServiceBroker::GetPVRManager().Clients()->DeleteAllRecordingsFromTrash() ==
134 PVR_ERROR_NO_ERROR;
138 class AsyncUndeleteRecording : public AsyncRecordingAction
140 private:
141 bool DoRun(const std::shared_ptr<CFileItem>& item) override
143 if (item->IsDeletedPVRRecording())
145 return item->GetPVRRecordingInfoTag()->Undelete();
147 else
149 CLog::LogF(LOGERROR, "Cannot undelete item '{}': no valid recording tag", item->GetPath());
150 return false;
155 class AsyncSetRecordingPlayCount : public AsyncRecordingAction
157 private:
158 bool DoRun(const std::shared_ptr<CFileItem>& item) override
160 const std::shared_ptr<CPVRClient> client = CServiceBroker::GetPVRManager().GetClient(*item);
161 if (client)
163 const std::shared_ptr<const CPVRRecording> recording = item->GetPVRRecordingInfoTag();
164 return client->SetRecordingPlayCount(*recording, recording->GetLocalPlayCount()) ==
165 PVR_ERROR_NO_ERROR;
167 return false;
171 class AsyncSetRecordingLifetime : public AsyncRecordingAction
173 private:
174 bool DoRun(const std::shared_ptr<CFileItem>& item) override
176 const std::shared_ptr<CPVRClient> client = CServiceBroker::GetPVRManager().GetClient(*item);
177 if (client)
178 return client->SetRecordingLifetime(*item->GetPVRRecordingInfoTag()) == PVR_ERROR_NO_ERROR;
179 return false;
183 } // unnamed namespace
185 bool CPVRGUIActionsRecordings::ShowRecordingInfo(const CFileItem& item) const
187 if (!item.IsPVRRecording())
189 CLog::LogF(LOGERROR, "No recording!");
190 return false;
193 CGUIDialogPVRRecordingInfo* pDlgInfo =
194 CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogPVRRecordingInfo>(
195 WINDOW_DIALOG_PVR_RECORDING_INFO);
196 if (!pDlgInfo)
198 CLog::LogF(LOGERROR, "Unable to get WINDOW_DIALOG_PVR_RECORDING_INFO!");
199 return false;
202 pDlgInfo->SetRecording(item);
203 pDlgInfo->Open();
204 return true;
207 bool CPVRGUIActionsRecordings::EditRecording(const CFileItem& item) const
209 const std::shared_ptr<CPVRRecording> recording = CPVRItem(item).GetRecording();
210 if (!recording)
212 CLog::LogF(LOGERROR, "No recording!");
213 return false;
216 std::shared_ptr<CPVRRecording> origRecording(new CPVRRecording);
217 origRecording->Update(*recording,
218 *CServiceBroker::GetPVRManager().GetClient(recording->ClientID()));
220 if (!ShowRecordingSettings(recording))
221 return false;
223 if (origRecording->m_strTitle != recording->m_strTitle)
225 if (!AsyncRenameRecording(recording->m_strTitle).Execute(item))
226 CLog::LogF(LOGERROR, "Renaming recording failed!");
229 if (origRecording->GetLocalPlayCount() != recording->GetLocalPlayCount())
231 if (!AsyncSetRecordingPlayCount().Execute(item))
232 CLog::LogF(LOGERROR, "Setting recording playcount failed!");
235 if (origRecording->LifeTime() != recording->LifeTime())
237 if (!AsyncSetRecordingLifetime().Execute(item))
238 CLog::LogF(LOGERROR, "Setting recording lifetime failed!");
241 return true;
244 bool CPVRGUIActionsRecordings::CanEditRecording(const CFileItem& item) const
246 return CGUIDialogPVRRecordingSettings::CanEditRecording(item);
249 bool CPVRGUIActionsRecordings::DeleteRecording(const CFileItem& item) const
251 if ((!item.IsPVRRecording() && !item.m_bIsFolder) || item.IsParentFolder())
252 return false;
254 if (!ConfirmDeleteRecording(item))
255 return false;
257 if (!AsyncDeleteRecording().Execute(item))
259 HELPERS::ShowOKDialogText(
260 CVariant{257},
261 CVariant{
262 19111}); // "Error", "PVR backend error. Check the log for more information about this message."
263 return false;
266 return true;
269 bool CPVRGUIActionsRecordings::ConfirmDeleteRecording(const CFileItem& item) const
271 return CGUIDialogYesNo::ShowAndGetInput(
272 CVariant{122}, // "Confirm delete"
273 item.m_bIsFolder
274 ? CVariant{19113} // "Delete all recordings in this folder?"
275 : item.GetPVRRecordingInfoTag()->IsDeleted()
276 ? CVariant{19294}
277 // "Remove this deleted recording from trash? This operation cannot be reverted."
278 : CVariant{19112}, // "Delete this recording?"
279 CVariant{""}, CVariant{item.GetLabel()});
282 bool CPVRGUIActionsRecordings::DeleteWatchedRecordings(const CFileItem& item) const
284 if (!item.m_bIsFolder || item.IsParentFolder())
285 return false;
287 if (!ConfirmDeleteWatchedRecordings(item))
288 return false;
290 if (!AsyncDeleteRecording(true).Execute(item))
292 HELPERS::ShowOKDialogText(
293 CVariant{257},
294 CVariant{
295 19111}); // "Error", "PVR backend error. Check the log for more information about this message."
296 return false;
299 return true;
302 bool CPVRGUIActionsRecordings::ConfirmDeleteWatchedRecordings(const CFileItem& item) const
304 return CGUIDialogYesNo::ShowAndGetInput(
305 CVariant{122}, // "Confirm delete"
306 CVariant{19328}, // "Delete all watched recordings in this folder?"
307 CVariant{""}, CVariant{item.GetLabel()});
310 bool CPVRGUIActionsRecordings::DeleteAllRecordingsFromTrash() const
312 if (!ConfirmDeleteAllRecordingsFromTrash())
313 return false;
315 if (!AsyncEmptyRecordingsTrash().Execute({}))
316 return false;
318 return true;
321 bool CPVRGUIActionsRecordings::ConfirmDeleteAllRecordingsFromTrash() const
323 return CGUIDialogYesNo::ShowAndGetInput(
324 CVariant{19292}, // "Delete all permanently"
325 CVariant{
326 19293}); // "Remove all deleted recordings from trash? This operation cannot be reverted."
329 bool CPVRGUIActionsRecordings::UndeleteRecording(const CFileItem& item) const
331 if (!item.IsDeletedPVRRecording())
332 return false;
334 if (!AsyncUndeleteRecording().Execute(item))
336 HELPERS::ShowOKDialogText(
337 CVariant{257},
338 CVariant{
339 19111}); // "Error", "PVR backend error. Check the log for more information about this message."
340 return false;
343 return true;
346 bool CPVRGUIActionsRecordings::ShowRecordingSettings(
347 const std::shared_ptr<CPVRRecording>& recording) const
349 CGUIDialogPVRRecordingSettings* pDlgInfo =
350 CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogPVRRecordingSettings>(
351 WINDOW_DIALOG_PVR_RECORDING_SETTING);
352 if (!pDlgInfo)
354 CLog::LogF(LOGERROR, "Unable to get WINDOW_DIALOG_PVR_RECORDING_SETTING!");
355 return false;
358 pDlgInfo->SetRecording(recording);
359 pDlgInfo->Open();
361 return pDlgInfo->IsConfirmed();