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.
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"
21 using namespace KODI::GUILIB
;
23 CGUIRSSControl::CGUIRSSControl(int parentID
,
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
),
36 m_channelColor(channelColor
),
37 m_headlineColor(headlineColor
),
38 m_scrollInfo(0, 0, labelInfo
.scrollSpeed
, "")
44 ControlType
= GUICONTROL_RSS
;
47 CGUIRSSControl::CGUIRSSControl(const CGUIRSSControl
& from
)
50 m_strRSSTags(from
.m_strRSSTags
),
51 m_label(from
.m_label
),
52 m_channelColor(from
.m_channelColor
),
53 m_headlineColor(from
.m_headlineColor
),
56 m_scrollInfo(from
.m_scrollInfo
)
60 m_stopped
= from
.m_stopped
;
62 ControlType
= GUICONTROL_RSS
;
65 CGUIRSSControl::~CGUIRSSControl(void)
67 std::unique_lock
<CCriticalSection
> lock(m_criticalSection
);
69 m_pReader
->SetObserver(NULL
);
73 void CGUIRSSControl::OnFocus()
78 void CGUIRSSControl::OnUnFocus()
83 void CGUIRSSControl::SetUrlSet(const int 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();
97 void CGUIRSSControl::Process(unsigned int currentTime
, CDirtyRegionList
&dirtyregions
)
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));
118 if (CRssManager::GetInstance().GetReader(GetID(), GetParentID(), this, m_pReader
))
120 m_scrollInfo
.m_pixelPos
= m_pReader
->m_savedScrollPixelPos
;
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
);
143 m_scrollInfo
.SetSpeed(0);
145 m_scrollInfo
.SetSpeed(m_label
.scrollSpeed
* (m_rtl
? -1 : 1));
147 if(m_label
.font
->UpdateScrollInfo(m_feed
, m_scrollInfo
))
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())
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
);
175 m_pReader
->CheckForUpdates();
176 m_pReader
->m_savedScrollPixelPos
= m_scrollInfo
.m_pixelPos
;
179 CGUIControl::Render();
182 CRect
CGUIRSSControl::CalcRenderRegion() const
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
);
196 void CGUIRSSControl::OnFeedRelease()