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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
/*
* Copyright (C) 2005-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 "GUIRSSControl.h"
#include "ServiceBroker.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "utils/ColorUtils.h"
#include "utils/RssManager.h"
#include "utils/RssReader.h"
#include "utils/StringUtils.h"
#include <mutex>
using namespace KODI::GUILIB;
CGUIRSSControl::CGUIRSSControl(int parentID,
int controlID,
float posX,
float posY,
float width,
float height,
const CLabelInfo& labelInfo,
const GUIINFO::CGUIInfoColor& channelColor,
const GUIINFO::CGUIInfoColor& headlineColor,
std::string& strRSSTags)
: CGUIControl(parentID, controlID, posX, posY, width, height),
m_strRSSTags(strRSSTags),
m_label(labelInfo),
m_channelColor(channelColor),
m_headlineColor(headlineColor),
m_scrollInfo(0, 0, labelInfo.scrollSpeed, "")
{
m_pReader = NULL;
m_rtl = false;
m_stopped = false;
m_urlset = 1;
ControlType = GUICONTROL_RSS;
}
CGUIRSSControl::CGUIRSSControl(const CGUIRSSControl& from)
: CGUIControl(from),
m_feed(),
m_strRSSTags(from.m_strRSSTags),
m_label(from.m_label),
m_channelColor(from.m_channelColor),
m_headlineColor(from.m_headlineColor),
m_vecUrls(),
m_vecIntervals(),
m_scrollInfo(from.m_scrollInfo)
{
m_pReader = NULL;
m_rtl = from.m_rtl;
m_stopped = from.m_stopped;
m_urlset = 1;
ControlType = GUICONTROL_RSS;
}
CGUIRSSControl::~CGUIRSSControl(void)
{
std::unique_lock<CCriticalSection> lock(m_criticalSection);
if (m_pReader)
m_pReader->SetObserver(NULL);
m_pReader = NULL;
}
void CGUIRSSControl::OnFocus()
{
m_stopped = true;
}
void CGUIRSSControl::OnUnFocus()
{
m_stopped = false;
}
void CGUIRSSControl::SetUrlSet(const int urlset)
{
m_urlset = urlset;
}
bool CGUIRSSControl::UpdateColors(const CGUIListItem* item)
{
bool changed = CGUIControl::UpdateColors(nullptr);
changed |= m_label.UpdateColors();
changed |= m_headlineColor.Update();
changed |= m_channelColor.Update();
return changed;
}
void CGUIRSSControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
{
bool dirty = false;
if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_LOOKANDFEEL_ENABLERSSFEEDS) && CRssManager::GetInstance().IsActive())
{
std::unique_lock<CCriticalSection> lock(m_criticalSection);
// Create RSS background/worker thread if needed
if (m_pReader == NULL)
{
RssUrls::const_iterator iter = CRssManager::GetInstance().GetUrls().find(m_urlset);
if (iter != CRssManager::GetInstance().GetUrls().end())
{
m_rtl = iter->second.rtl;
m_vecUrls = iter->second.url;
m_vecIntervals = iter->second.interval;
m_scrollInfo.SetSpeed(m_label.scrollSpeed * (m_rtl ? -1 : 1));
}
dirty = true;
if (CRssManager::GetInstance().GetReader(GetID(), GetParentID(), this, m_pReader))
{
m_scrollInfo.m_pixelPos = m_pReader->m_savedScrollPixelPos;
}
else
{
if (m_strRSSTags != "")
{
std::vector<std::string> tags = StringUtils::Split(m_strRSSTags, ",");
for (const std::string& i : tags)
m_pReader->AddTag(i);
}
// use half the width of the control as spacing between feeds, and double this between feed sets
float spaceWidth = (m_label.font) ? m_label.font->GetCharWidth(L' ') : 15;
m_pReader->Create(this, m_vecUrls, m_vecIntervals, (int)(0.5f*GetWidth() / spaceWidth) + 1, m_rtl);
}
}
if(m_dirty)
dirty = true;
m_dirty = false;
if (m_label.font)
{
if ( m_stopped )
m_scrollInfo.SetSpeed(0);
else
m_scrollInfo.SetSpeed(m_label.scrollSpeed * (m_rtl ? -1 : 1));
if(m_label.font->UpdateScrollInfo(m_feed, m_scrollInfo))
dirty = true;
}
}
if(dirty)
MarkDirtyRegion();
CGUIControl::Process(currentTime, dirtyregions);
}
void CGUIRSSControl::Render()
{
// only render the control if they are enabled
if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_LOOKANDFEEL_ENABLERSSFEEDS) && CRssManager::GetInstance().IsActive())
{
if (m_label.font)
{
std::vector<UTILS::COLOR::Color> colors;
colors.push_back(m_label.textColor);
colors.push_back(m_headlineColor);
colors.push_back(m_channelColor);
m_label.font->DrawScrollingText(m_posX, m_posY, colors, m_label.shadowColor, m_feed, 0, m_width, m_scrollInfo);
}
if (m_pReader)
{
m_pReader->CheckForUpdates();
m_pReader->m_savedScrollPixelPos = m_scrollInfo.m_pixelPos;
}
}
CGUIControl::Render();
}
CRect CGUIRSSControl::CalcRenderRegion() const
{
if (m_label.font)
return CRect(m_posX, m_posY, m_posX + m_width, m_posY + m_label.font->GetTextHeight(1));
return CGUIControl::CalcRenderRegion();
}
void CGUIRSSControl::OnFeedUpdate(const vecText &feed)
{
std::unique_lock<CCriticalSection> lock(m_criticalSection);
m_feed = feed;
m_dirty = true;
}
void CGUIRSSControl::OnFeedRelease()
{
m_pReader = NULL;
}
|