| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include "XBDateTime.h" |
| 12 |
|
| 13 |
#include <functional> |
| 14 |
#include <map> |
| 15 |
#include <memory> |
| 16 |
#include <unordered_map> |
| 17 |
#include <utility> |
| 18 |
#include <vector> |
| 19 |
|
| 20 |
class CFileItem; |
| 21 |
class CFileItemList; |
| 22 |
|
| 23 |
namespace PVR |
| 24 |
{ |
| 25 |
struct GridItem |
| 26 |
{ |
| 27 |
GridItem(const std::shared_ptr<CFileItem>& _item, float _width, int _startBlock, int _endBlock) |
| 28 |
: item(_item), originWidth(_width), width(_width), startBlock(_startBlock), endBlock(_endBlock) |
| 29 |
{ |
| 30 |
} |
| 31 |
|
| 32 |
bool operator==(const GridItem& other) const |
| 33 |
{ |
| 34 |
return (startBlock == other.startBlock && endBlock == other.endBlock); |
| 35 |
} |
| 36 |
|
| 37 |
std::shared_ptr<CFileItem> item; |
| 38 |
float originWidth = 0.0f; |
| 39 |
float width = 0.0f; |
| 40 |
int startBlock = 0; |
| 41 |
int endBlock = 0; |
| 42 |
}; |
| 43 |
|
| 44 |
class CPVREpgInfoTag; |
| 45 |
|
| 46 |
class CGUIEPGGridContainerModel |
| 47 |
{ |
| 48 |
public: |
| 49 |
static constexpr int MINSPERBLOCK = 5; |
| 50 |
|
| 51 |
CGUIEPGGridContainerModel() = default; |
| 52 |
virtual ~CGUIEPGGridContainerModel() = default; |
| 53 |
|
| 54 |
void Initialize(const std::unique_ptr<CFileItemList>& items, |
| 55 |
const CDateTime& gridStart, |
| 56 |
const CDateTime& gridEnd, |
| 57 |
int iFirstChannel, |
| 58 |
int iChannelsPerPage, |
| 59 |
int iFirstBlock, |
| 60 |
int iBlocksPerPage, |
| 61 |
int iRulerUnit, |
| 62 |
float fBlockSize); |
| 63 |
void SetInvalid(); |
| 64 |
|
| 65 |
static const int INVALID_INDEX = -1; |
| 66 |
void FindChannelAndBlockIndex(int channelUid, |
| 67 |
unsigned int broadcastUid, |
| 68 |
int eventOffset, |
| 69 |
int& newChannelIndex, |
| 70 |
int& newBlockIndex) const; |
| 71 |
|
| 72 |
void FreeChannelMemory(int keepStart, int keepEnd); |
| 73 |
bool FreeProgrammeMemory(int firstChannel, int lastChannel, int firstBlock, int lastBlock); |
| 74 |
void FreeRulerMemory(int keepStart, int keepEnd); |
| 75 |
|
| 76 |
std::shared_ptr<CFileItem> GetChannelItem(int iIndex) const { return m_channelItems[iIndex]; } |
| 77 |
bool HasChannelItems() const { return !m_channelItems.empty(); } |
| 78 |
int ChannelItemsSize() const { return static_cast<int>(m_channelItems.size()); } |
| 79 |
int GetLastChannel() const |
| 80 |
{ |
| 81 |
return m_channelItems.empty() ? -1 : static_cast<int>(m_channelItems.size()) - 1; |
| 82 |
} |
| 83 |
|
| 84 |
std::shared_ptr<CFileItem> GetRulerItem(int iIndex) const { return m_rulerItems[iIndex]; } |
| 85 |
int RulerItemsSize() const { return static_cast<int>(m_rulerItems.size()); } |
| 86 |
|
| 87 |
int GridItemsSize() const { return m_blocks; } |
| 88 |
bool IsSameGridItem(int iChannel, int iBlock1, int iBlock2) const; |
| 89 |
std::shared_ptr<CFileItem> GetGridItem(int iChannel, int iBlock) const; |
| 90 |
int GetGridItemStartBlock(int iChannel, int iBlock) const; |
| 91 |
int GetGridItemEndBlock(int iChannel, int iBlock) const; |
| 92 |
CDateTime GetGridItemEndTime(int iChannel, int iBlock) const; |
| 93 |
float GetGridItemWidth(int iChannel, int iBlock) const; |
| 94 |
float GetGridItemOriginWidth(int iChannel, int iBlock) const; |
| 95 |
void DecreaseGridItemWidth(int iChannel, int iBlock, float fSize); |
| 96 |
|
| 97 |
bool IsZeroGridDuration() const { return (m_gridEnd - m_gridStart) == CDateTimeSpan(0, 0, 0, 0); } |
| 98 |
const CDateTime& GetGridStart() const { return m_gridStart; } |
| 99 |
const CDateTime& GetGridEnd() const { return m_gridEnd; } |
| 100 |
unsigned int GetGridStartPadding() const; |
| 101 |
|
| 102 |
unsigned int GetPageNowOffset() const; |
| 103 |
int GetNowBlock() const; |
| 104 |
int GetLastBlock() const { return m_blocks - 1; } |
| 105 |
|
| 106 |
CDateTime GetStartTimeForBlock(int block) const; |
| 107 |
int GetBlock(const CDateTime& datetime) const; |
| 108 |
int GetFirstEventBlock(const std::shared_ptr<const CPVREpgInfoTag>& event) const; |
| 109 |
int GetLastEventBlock(const std::shared_ptr<const CPVREpgInfoTag>& event) const; |
| 110 |
bool IsEventMemberOfBlock(const std::shared_ptr<const CPVREpgInfoTag>& event, int iBlock) const; |
| 111 |
|
| 112 |
std::unique_ptr<CFileItemList> GetCurrentTimeLineItems(int firstChannel, int numChannels) const; |
| 113 |
|
| 114 |
private: |
| 115 |
GridItem* GetGridItemPtr(int iChannel, int iBlock) const; |
| 116 |
std::shared_ptr<CFileItem> CreateGapItem(int iChannel) const; |
| 117 |
std::shared_ptr<CFileItem> GetItem(int iChannel, int iBlock) const; |
| 118 |
|
| 119 |
std::vector<std::shared_ptr<CPVREpgInfoTag>> GetEPGTimeline(int iChannel, |
| 120 |
const CDateTime& minEventEnd, |
| 121 |
const CDateTime& maxEventStart) const; |
| 122 |
|
| 123 |
struct EpgTags |
| 124 |
{ |
| 125 |
std::vector<std::shared_ptr<CFileItem>> tags; |
| 126 |
int firstBlock = -1; |
| 127 |
int lastBlock = -1; |
| 128 |
}; |
| 129 |
|
| 130 |
using EpgTagsMap = std::unordered_map<int, EpgTags>; |
| 131 |
|
| 132 |
std::shared_ptr<CFileItem> CreateEpgTags(int iChannel, int iBlock) const; |
| 133 |
std::shared_ptr<CFileItem> GetEpgTags(EpgTagsMap::iterator& itEpg, |
| 134 |
int iChannel, |
| 135 |
int iBlock) const; |
| 136 |
std::shared_ptr<CFileItem> GetEpgTagsBefore(EpgTags& epgTags, int iChannel, int iBlock) const; |
| 137 |
std::shared_ptr<CFileItem> GetEpgTagsAfter(EpgTags& epgTags, int iChannel, int iBlock) const; |
| 138 |
|
| 139 |
mutable EpgTagsMap m_epgItems; |
| 140 |
|
| 141 |
CDateTime m_gridStart; |
| 142 |
CDateTime m_gridEnd; |
| 143 |
|
| 144 |
std::vector<std::shared_ptr<CFileItem>> m_channelItems; |
| 145 |
std::vector<std::shared_ptr<CFileItem>> m_rulerItems; |
| 146 |
|
| 147 |
struct GridCoordinates |
| 148 |
{ |
| 149 |
GridCoordinates(int _channel, int _block) : channel(_channel), block(_block) {} |
| 150 |
|
| 151 |
bool operator==(const GridCoordinates& other) const |
| 152 |
{ |
| 153 |
return (channel == other.channel && block == other.block); |
| 154 |
} |
| 155 |
|
| 156 |
int channel = 0; |
| 157 |
int block = 0; |
| 158 |
}; |
| 159 |
|
| 160 |
struct GridCoordinatesHash |
| 161 |
{ |
| 162 |
std::size_t operator()(const GridCoordinates& coordinates) const |
| 163 |
{ |
| 164 |
return std::hash<int>()(coordinates.channel) ^ std::hash<int>()(coordinates.block); |
| 165 |
} |
| 166 |
}; |
| 167 |
|
| 168 |
mutable std::unordered_map<GridCoordinates, GridItem, GridCoordinatesHash> m_gridIndex; |
| 169 |
|
| 170 |
int m_blocks = 0; |
| 171 |
float m_fBlockSize = 0.0f; |
| 172 |
|
| 173 |
int m_firstActiveChannel = 0; |
| 174 |
int m_lastActiveChannel = 0; |
| 175 |
int m_firstActiveBlock = 0; |
| 176 |
int m_lastActiveBlock = 0; |
| 177 |
}; |
| 178 |
} |