2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "GUIRSSControl.h"
22 #include "GUIWindowManager.h"
23 #include "settings/Settings.h"
24 #include "threads/CriticalSection.h"
25 #include "threads/SingleLock.h"
26 #include "utils/RssManager.h"
27 #include "utils/RssReader.h"
28 #include "utils/StringUtils.h"
32 CGUIRSSControl::CGUIRSSControl(int parentID, int controlID, float posX, float posY, float width, float height, const CLabelInfo& labelInfo, const CGUIInfoColor &channelColor, const CGUIInfoColor &headlineColor, CStdString& strRSSTags)
33 : CGUIControl(parentID, controlID, posX, posY, width, height),
35 m_channelColor(channelColor),
36 m_headlineColor(headlineColor),
37 m_scrollInfo(0,0,labelInfo.scrollSpeed,""),
40 m_strRSSTags = strRSSTags;
46 ControlType = GUICONTROL_RSS;
49 CGUIRSSControl::CGUIRSSControl(const CGUIRSSControl &from)
52 m_label(from.m_label),
53 m_channelColor(from.m_channelColor),
54 m_headlineColor(from.m_headlineColor),
57 m_scrollInfo(from.m_scrollInfo),
60 m_strRSSTags = from.m_strRSSTags;
63 m_stopped = from.m_stopped;
65 ControlType = GUICONTROL_RSS;
68 CGUIRSSControl::~CGUIRSSControl(void)
70 CSingleLock lock(m_criticalSection);
72 m_pReader->SetObserver(NULL);
76 void CGUIRSSControl::OnFocus()
81 void CGUIRSSControl::OnUnFocus()
86 void CGUIRSSControl::SetUrlSet(const int urlset)
91 bool CGUIRSSControl::UpdateColors()
93 bool changed = CGUIControl::UpdateColors();
94 changed |= m_label.UpdateColors();
95 changed |= m_headlineColor.Update();
96 changed |= m_channelColor.Update();
100 void CGUIRSSControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
103 if (CSettings::Get().GetBool("lookandfeel.enablerssfeeds") && CRssManager::Get().IsActive())
105 CSingleLock lock(m_criticalSection);
106 // Create RSS background/worker thread if needed
107 if (m_pReader == NULL)
110 RssUrls::const_iterator iter = CRssManager::Get().GetUrls().find(m_urlset);
111 if (iter != CRssManager::Get().GetUrls().end())
113 m_rtl = iter->second.rtl;
114 m_vecUrls = iter->second.url;
115 m_vecIntervals = iter->second.interval;
116 if (m_scrollInfo.pixelSpeed > 0 && m_rtl)
117 m_scrollInfo.pixelSpeed *= -1;
118 else if (m_scrollInfo.pixelSpeed < 0 && !m_rtl)
119 m_scrollInfo.pixelSpeed *= -1;
124 if (CRssManager::Get().GetReader(GetID(), GetParentID(), this, m_pReader))
125 m_scrollInfo.characterPos = m_pReader->m_SavedScrollPos;
128 if (m_strRSSTags != "")
130 CStdStringArray vecSplitTags;
132 StringUtils::SplitString(m_strRSSTags, ",", vecSplitTags);
134 for (unsigned int i = 0;i < vecSplitTags.size();i++)
135 m_pReader->AddTag(vecSplitTags[i]);
137 // use half the width of the control as spacing between feeds, and double this between feed sets
138 float spaceWidth = (m_label.font) ? m_label.font->GetCharWidth(L' ') : 15;
139 m_pReader->Create(this, m_vecUrls, m_vecIntervals, (int)(0.5f*GetWidth() / spaceWidth) + 1, m_rtl);
150 m_scrollInfo.SetSpeed(0);
152 m_scrollInfo.SetSpeed(m_label.scrollSpeed);
154 if(m_label.font->UpdateScrollInfo(m_feed, m_scrollInfo))
162 CGUIControl::Process(currentTime, dirtyregions);
165 void CGUIRSSControl::Render()
167 // only render the control if they are enabled
168 if (CSettings::Get().GetBool("lookandfeel.enablerssfeeds") && CRssManager::Get().IsActive())
174 colors.push_back(m_label.textColor);
175 colors.push_back(m_headlineColor);
176 colors.push_back(m_channelColor);
177 m_label.font->DrawScrollingText(m_posX, m_posY, colors, m_label.shadowColor, m_feed, 0, m_width, m_scrollInfo);
182 m_pReader->CheckForUpdates();
183 m_pReader->m_SavedScrollPos = m_scrollInfo.characterPos;
186 CGUIControl::Render();
189 CRect CGUIRSSControl::CalcRenderRegion() const
192 return CRect(m_posX, m_posY, m_posX + m_width, m_posY + m_label.font->GetTextHeight(1));
193 return CGUIControl::CalcRenderRegion();
196 void CGUIRSSControl::OnFeedUpdate(const vecText &feed)
198 CSingleLock lock(m_criticalSection);
203 void CGUIRSSControl::OnFeedRelease()