[WASAPI] fix stream types and frequencies enumeration
[xbmc.git] / xbmc / guilib / GUIRSSControl.cpp
blob32dec47574468bd62ed0aaf65c7ca97a661ff6e4
1 /*
2 * Copyright (C) 2005-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 "GUIRSSControl.h"
11 #include "ServiceBroker.h"
12 #include "settings/Settings.h"
13 #include "settings/SettingsComponent.h"
14 #include "utils/ColorUtils.h"
15 #include "utils/RssManager.h"
16 #include "utils/RssReader.h"
17 #include "utils/StringUtils.h"
19 #include <mutex>
21 using namespace KODI::GUILIB;
23 CGUIRSSControl::CGUIRSSControl(int parentID,
24 int controlID,
25 float posX,
26 float posY,
27 float width,
28 float height,
29 const CLabelInfo& labelInfo,
30 const GUIINFO::CGUIInfoColor& channelColor,
31 const GUIINFO::CGUIInfoColor& headlineColor,
32 std::string& strRSSTags)
33 : CGUIControl(parentID, controlID, posX, posY, width, height),
34 m_strRSSTags(strRSSTags),
35 m_label(labelInfo),
36 m_channelColor(channelColor),
37 m_headlineColor(headlineColor),
38 m_scrollInfo(0, 0, labelInfo.scrollSpeed, "")
40 m_pReader = NULL;
41 m_rtl = false;
42 m_stopped = false;
43 m_urlset = 1;
44 ControlType = GUICONTROL_RSS;
47 CGUIRSSControl::CGUIRSSControl(const CGUIRSSControl& from)
48 : CGUIControl(from),
49 m_feed(),
50 m_strRSSTags(from.m_strRSSTags),
51 m_label(from.m_label),
52 m_channelColor(from.m_channelColor),
53 m_headlineColor(from.m_headlineColor),
54 m_vecUrls(),
55 m_vecIntervals(),
56 m_scrollInfo(from.m_scrollInfo)
58 m_pReader = NULL;
59 m_rtl = from.m_rtl;
60 m_stopped = from.m_stopped;
61 m_urlset = 1;
62 ControlType = GUICONTROL_RSS;
65 CGUIRSSControl::~CGUIRSSControl(void)
67 std::unique_lock<CCriticalSection> lock(m_criticalSection);
68 if (m_pReader)
69 m_pReader->SetObserver(NULL);
70 m_pReader = NULL;
73 void CGUIRSSControl::OnFocus()
75 m_stopped = true;
78 void CGUIRSSControl::OnUnFocus()
80 m_stopped = false;
83 void CGUIRSSControl::SetUrlSet(const int urlset)
85 m_urlset = urlset;
88 bool CGUIRSSControl::UpdateColors(const CGUIListItem* item)
90 bool changed = CGUIControl::UpdateColors(nullptr);
91 changed |= m_label.UpdateColors();
92 changed |= m_headlineColor.Update();
93 changed |= m_channelColor.Update();
94 return changed;
97 void CGUIRSSControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
99 bool dirty = false;
100 if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_LOOKANDFEEL_ENABLERSSFEEDS) && CRssManager::GetInstance().IsActive())
102 std::unique_lock<CCriticalSection> lock(m_criticalSection);
103 // Create RSS background/worker thread if needed
104 if (m_pReader == NULL)
107 RssUrls::const_iterator iter = CRssManager::GetInstance().GetUrls().find(m_urlset);
108 if (iter != CRssManager::GetInstance().GetUrls().end())
110 m_rtl = iter->second.rtl;
111 m_vecUrls = iter->second.url;
112 m_vecIntervals = iter->second.interval;
113 m_scrollInfo.SetSpeed(m_label.scrollSpeed * (m_rtl ? -1 : 1));
116 dirty = true;
118 if (CRssManager::GetInstance().GetReader(GetID(), GetParentID(), this, m_pReader))
120 m_scrollInfo.m_pixelPos = m_pReader->m_savedScrollPixelPos;
122 else
124 if (m_strRSSTags != "")
126 std::vector<std::string> tags = StringUtils::Split(m_strRSSTags, ",");
127 for (const std::string& i : tags)
128 m_pReader->AddTag(i);
130 // use half the width of the control as spacing between feeds, and double this between feed sets
131 float spaceWidth = (m_label.font) ? m_label.font->GetCharWidth(L' ') : 15;
132 m_pReader->Create(this, m_vecUrls, m_vecIntervals, (int)(0.5f*GetWidth() / spaceWidth) + 1, m_rtl);
136 if(m_dirty)
137 dirty = true;
138 m_dirty = false;
140 if (m_label.font)
142 if ( m_stopped )
143 m_scrollInfo.SetSpeed(0);
144 else
145 m_scrollInfo.SetSpeed(m_label.scrollSpeed * (m_rtl ? -1 : 1));
147 if(m_label.font->UpdateScrollInfo(m_feed, m_scrollInfo))
148 dirty = true;
152 if(dirty)
153 MarkDirtyRegion();
155 CGUIControl::Process(currentTime, dirtyregions);
158 void CGUIRSSControl::Render()
160 // only render the control if they are enabled
161 if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_LOOKANDFEEL_ENABLERSSFEEDS) && CRssManager::GetInstance().IsActive())
164 if (m_label.font)
166 std::vector<KODI::UTILS::COLOR::Color> colors;
167 colors.push_back(m_label.textColor);
168 colors.push_back(m_headlineColor);
169 colors.push_back(m_channelColor);
170 m_label.font->DrawScrollingText(m_posX, m_posY, colors, m_label.shadowColor, m_feed, 0, m_width, m_scrollInfo);
173 if (m_pReader)
175 m_pReader->CheckForUpdates();
176 m_pReader->m_savedScrollPixelPos = m_scrollInfo.m_pixelPos;
179 CGUIControl::Render();
182 CRect CGUIRSSControl::CalcRenderRegion() const
184 if (m_label.font)
185 return CRect(m_posX, m_posY, m_posX + m_width, m_posY + m_label.font->GetTextHeight(1));
186 return CGUIControl::CalcRenderRegion();
189 void CGUIRSSControl::OnFeedUpdate(const vecText &feed)
191 std::unique_lock<CCriticalSection> lock(m_criticalSection);
192 m_feed = feed;
193 m_dirty = true;
196 void CGUIRSSControl::OnFeedRelease()
198 m_pReader = NULL;