1 /*
2  *  Copyright (C) 2016-2018 Team Kodi
3  *  This file is part of Kodi - https://kodi.tv
4  *
5  *  SPDX-License-Identifier: GPL-2.0-or-later
6  *  See LICENSES/README.md for more information.
7  */
8 
9 #include "PVRItem.h"
10 
11 #include "FileItem.h"
12 #include "ServiceBroker.h"
13 #include "pvr/PVRManager.h"
14 #include "pvr/channels/PVRChannel.h"
15 #include "pvr/channels/PVRChannelGroupsContainer.h"
16 #include "pvr/epg/EpgInfoTag.h"
17 #include "pvr/recordings/PVRRecording.h"
18 #include "pvr/recordings/PVRRecordings.h"
19 #include "pvr/timers/PVRTimerInfoTag.h"
20 #include "pvr/timers/PVRTimers.h"
21 #include "utils/log.h"
22 
23 #include <memory>
24 
25 namespace PVR
26 {
GetEpgInfoTag() const27   std::shared_ptr<CPVREpgInfoTag> CPVRItem::GetEpgInfoTag() const
28   {
29     if (m_item->IsEPG())
30     {
31       return m_item->GetEPGInfoTag();
32     }
33     else if (m_item->IsPVRChannel())
34     {
35       return m_item->GetPVRChannelInfoTag()->GetEPGNow();
36     }
37     else if (m_item->IsPVRTimer())
38     {
39       return m_item->GetPVRTimerInfoTag()->GetEpgInfoTag();
40     }
41     else
42     {
43       CLog::LogF(LOGERROR, "Unsupported item type!");
44     }
45     return std::shared_ptr<CPVREpgInfoTag>();
46   }
47 
GetNextEpgInfoTag() const48   std::shared_ptr<CPVREpgInfoTag> CPVRItem::GetNextEpgInfoTag() const
49   {
50     if (m_item->IsEPG())
51     {
52       const std::shared_ptr<CPVRChannel> channel = CServiceBroker::GetPVRManager().ChannelGroups()->GetChannelForEpgTag(m_item->GetEPGInfoTag());
53       if (channel)
54         return channel->GetEPGNext();
55     }
56     else if (m_item->IsPVRChannel())
57     {
58       return m_item->GetPVRChannelInfoTag()->GetEPGNext();
59     }
60     else if (m_item->IsPVRTimer())
61     {
62       const std::shared_ptr<CPVRChannel> channel = m_item->GetPVRTimerInfoTag()->Channel();
63       if (channel)
64         return channel->GetEPGNext();
65     }
66     else
67     {
68       CLog::LogF(LOGERROR, "Unsupported item type!");
69     }
70     return std::shared_ptr<CPVREpgInfoTag>();
71   }
72 
GetChannel() const73   std::shared_ptr<CPVRChannel> CPVRItem::GetChannel() const
74   {
75     if (m_item->IsPVRChannel())
76     {
77       return m_item->GetPVRChannelInfoTag();
78     }
79     else if (m_item->IsEPG())
80     {
81       return CServiceBroker::GetPVRManager().ChannelGroups()->GetChannelForEpgTag(m_item->GetEPGInfoTag());
82     }
83     else if (m_item->IsPVRTimer())
84     {
85       return m_item->GetPVRTimerInfoTag()->Channel();
86     }
87     else
88     {
89       CLog::LogF(LOGERROR, "Unsupported item type!");
90     }
91     return std::shared_ptr<CPVRChannel>();
92   }
93 
GetTimerInfoTag() const94   std::shared_ptr<CPVRTimerInfoTag> CPVRItem::GetTimerInfoTag() const
95   {
96     if (m_item->IsPVRTimer())
97     {
98       return m_item->GetPVRTimerInfoTag();
99     }
100     else if (m_item->IsEPG())
101     {
102       return CServiceBroker::GetPVRManager().Timers()->GetTimerForEpgTag(m_item->GetEPGInfoTag());
103     }
104     else if (m_item->IsPVRChannel())
105     {
106       return CServiceBroker::GetPVRManager().Timers()->GetActiveTimerForChannel(m_item->GetPVRChannelInfoTag());
107     }
108     else
109     {
110       CLog::LogF(LOGERROR, "Unsupported item type!");
111     }
112     return std::shared_ptr<CPVRTimerInfoTag>();
113   }
114 
GetRecording() const115   std::shared_ptr<CPVRRecording> CPVRItem::GetRecording() const
116   {
117     if (m_item->IsPVRRecording())
118     {
119       return m_item->GetPVRRecordingInfoTag();
120     }
121     else if (m_item->IsEPG())
122     {
123       return CServiceBroker::GetPVRManager().Recordings()->GetRecordingForEpgTag(m_item->GetEPGInfoTag());
124     }
125     else
126     {
127       CLog::LogF(LOGERROR, "Unsupported item type!");
128     }
129     return std::shared_ptr<CPVRRecording>();
130   }
131 
IsRadio() const132   bool CPVRItem::IsRadio() const
133   {
134     if (m_item->IsPVRChannel())
135     {
136       return m_item->GetPVRChannelInfoTag()->IsRadio();
137     }
138     else if (m_item->IsEPG())
139     {
140       return m_item->GetEPGInfoTag()->IsRadio();
141     }
142     else if (m_item->IsPVRRecording())
143     {
144       return m_item->GetPVRRecordingInfoTag()->IsRadio();
145     }
146     else if (m_item->IsPVRTimer())
147     {
148       return m_item->GetPVRTimerInfoTag()->m_bIsRadio;
149     }
150     else
151     {
152       CLog::LogF(LOGERROR, "Unsupported item type!");
153     }
154     return false;
155   }
156 
157 } // namespace PVR
158