summaryrefslogtreecommitdiffstats
path: root/xbmc/pvr/PVRItem.cpp
blob: 5eee911bdba41a70fde7cb0e8eeb6325dea927ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 *  Copyright (C) 2016-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "PVRItem.h"

#include "FileItem.h"
#include "ServiceBroker.h"
#include "pvr/PVRManager.h"
#include "pvr/channels/PVRChannel.h"
#include "pvr/channels/PVRChannelGroupsContainer.h"
#include "pvr/epg/EpgInfoTag.h"
#include "pvr/recordings/PVRRecording.h"
#include "pvr/recordings/PVRRecordings.h"
#include "pvr/timers/PVRTimerInfoTag.h"
#include "pvr/timers/PVRTimers.h"
#include "utils/URIUtils.h"
#include "utils/log.h"

#include <memory>

namespace PVR
{
std::shared_ptr<CPVREpgInfoTag> CPVRItem::GetEpgInfoTag() const
{
  if (m_item->IsEPG())
  {
    return m_item->GetEPGInfoTag();
  }
  else if (m_item->IsPVRChannel())
  {
    return m_item->GetPVRChannelInfoTag()->GetEPGNow();
  }
  else if (m_item->IsPVRTimer())
  {
    return m_item->GetPVRTimerInfoTag()->GetEpgInfoTag();
  }
  else if (URIUtils::IsPVR(m_item->GetDynPath()))
  {
    CLog::LogF(LOGERROR, "Unsupported item type!");
  }
  return {};
}

std::shared_ptr<CPVREpgInfoTag> CPVRItem::GetNextEpgInfoTag() const
{
  if (m_item->IsEPG())
  {
    const std::shared_ptr<CPVRChannel> channel =
        CServiceBroker::GetPVRManager().ChannelGroups()->GetChannelForEpgTag(
            m_item->GetEPGInfoTag());
    if (channel)
      return channel->GetEPGNext();
  }
  else if (m_item->IsPVRChannel())
  {
    return m_item->GetPVRChannelInfoTag()->GetEPGNext();
  }
  else if (m_item->IsPVRTimer())
  {
    const std::shared_ptr<CPVRChannel> channel = m_item->GetPVRTimerInfoTag()->Channel();
    if (channel)
      return channel->GetEPGNext();
  }
  else if (URIUtils::IsPVR(m_item->GetDynPath()))
  {
    CLog::LogF(LOGERROR, "Unsupported item type!");
  }
  return {};
}

std::shared_ptr<CPVRChannel> CPVRItem::GetChannel() const
{
  if (m_item->IsPVRChannel())
  {
    return m_item->GetPVRChannelInfoTag();
  }
  else if (m_item->IsEPG())
  {
    return CServiceBroker::GetPVRManager().ChannelGroups()->GetChannelForEpgTag(
        m_item->GetEPGInfoTag());
  }
  else if (m_item->IsPVRTimer())
  {
    return m_item->GetPVRTimerInfoTag()->Channel();
  }
  else if (m_item->IsPVRRecording())
  {
    return m_item->GetPVRRecordingInfoTag()->Channel();
  }
  else if (URIUtils::IsPVR(m_item->GetDynPath()))
  {
    CLog::LogF(LOGERROR, "Unsupported item type!");
  }
  return {};
}

std::shared_ptr<CPVRTimerInfoTag> CPVRItem::GetTimerInfoTag() const
{
  if (m_item->IsPVRTimer())
  {
    return m_item->GetPVRTimerInfoTag();
  }
  else if (m_item->IsEPG())
  {
    return CServiceBroker::GetPVRManager().Timers()->GetTimerForEpgTag(m_item->GetEPGInfoTag());
  }
  else if (m_item->IsPVRChannel())
  {
    return CServiceBroker::GetPVRManager().Timers()->GetActiveTimerForChannel(
        m_item->GetPVRChannelInfoTag());
  }
  else if (URIUtils::IsPVR(m_item->GetDynPath()))
  {
    CLog::LogF(LOGERROR, "Unsupported item type!");
  }
  return {};
}

std::shared_ptr<CPVRRecording> CPVRItem::GetRecording() const
{
  if (m_item->IsPVRRecording())
  {
    return m_item->GetPVRRecordingInfoTag();
  }
  else if (m_item->IsEPG())
  {
    return CServiceBroker::GetPVRManager().Recordings()->GetRecordingForEpgTag(
        m_item->GetEPGInfoTag());
  }
  else if (URIUtils::IsPVR(m_item->GetDynPath()))
  {
    CLog::LogF(LOGERROR, "Unsupported item type!");
  }
  return {};
}

bool CPVRItem::IsRadio() const
{
  if (m_item->IsPVRChannel())
  {
    return m_item->GetPVRChannelInfoTag()->IsRadio();
  }
  else if (m_item->IsEPG())
  {
    return m_item->GetEPGInfoTag()->IsRadio();
  }
  else if (m_item->IsPVRRecording())
  {
    return m_item->GetPVRRecordingInfoTag()->IsRadio();
  }
  else if (m_item->IsPVRTimer())
  {
    return m_item->GetPVRTimerInfoTag()->IsRadio();
  }
  else if (URIUtils::IsPVR(m_item->GetDynPath()))
  {
    CLog::LogF(LOGERROR, "Unsupported item type!");
  }
  return false;
}

} // namespace PVR