2 * Copyright (C) 2012-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 "Application.h"
22 #include "PVRGUIInfo.h"
23 #include "guilib/LocalizeStrings.h"
24 #include "utils/StringUtils.h"
25 #include "GUIInfoManager.h"
27 #include "threads/SingleLock.h"
28 #include "PVRManager.h"
29 #include "pvr/addons/PVRClients.h"
30 #include "pvr/timers/PVRTimers.h"
31 #include "pvr/recordings/PVRRecordings.h"
32 #include "pvr/channels/PVRChannel.h"
33 #include "epg/EpgInfoTag.h"
34 #include "settings/AdvancedSettings.h"
35 #include "settings/Settings.h"
41 CPVRGUIInfo::CPVRGUIInfo(void) :
42 CThread("PVRGUIInfo"),
48 CPVRGUIInfo::~CPVRGUIInfo(void)
53 void CPVRGUIInfo::ResetProperties(void)
55 CSingleLock lock(m_critSection);
56 m_strActiveTimerTitle = StringUtils::EmptyString;
57 m_strActiveTimerChannelName = StringUtils::EmptyString;
58 m_strActiveTimerChannelIcon = StringUtils::EmptyString;
59 m_strActiveTimerTime = StringUtils::EmptyString;
60 m_strNextTimerInfo = StringUtils::EmptyString;
61 m_strNextRecordingTitle = StringUtils::EmptyString;
62 m_strNextRecordingChannelName = StringUtils::EmptyString;
63 m_strNextRecordingChannelIcon = StringUtils::EmptyString;
64 m_strNextRecordingTime = StringUtils::EmptyString;
66 m_bHasRecordings = false;
67 m_iRecordingTimerAmount = 0;
69 m_strPlayingClientName = StringUtils::EmptyString;
70 m_strBackendName = StringUtils::EmptyString;
71 m_strBackendVersion = StringUtils::EmptyString;
72 m_strBackendHost = StringUtils::EmptyString;
73 m_strBackendDiskspace = StringUtils::EmptyString;
74 m_strBackendTimers = StringUtils::EmptyString;
75 m_strBackendRecordings = StringUtils::EmptyString;
76 m_strBackendChannels = StringUtils::EmptyString;
77 m_strTotalDiskspace = StringUtils::EmptyString;
78 m_iAddonInfoToggleStart = 0;
79 m_iAddonInfoToggleCurrent = 0;
80 m_iTimerInfoToggleStart = 0;
81 m_iTimerInfoToggleCurrent = 0;
82 m_ToggleShowInfo.SetInfinite();
84 m_bHasNonRecordingTimers = false;
85 m_bIsPlayingTV = false;
86 m_bIsPlayingRadio = false;
87 m_bIsPlayingRecording = false;
88 m_bIsPlayingEncryptedStream = false;
91 ClearQualityInfo(m_qualityInfo);
94 void CPVRGUIInfo::ClearQualityInfo(PVR_SIGNAL_STATUS &qualityInfo)
96 memset(&qualityInfo, 0, sizeof(qualityInfo));
97 strncpy(qualityInfo.strAdapterName, g_localizeStrings.Get(13106).c_str(), PVR_ADDON_NAME_STRING_LENGTH - 1);
98 strncpy(qualityInfo.strAdapterStatus, g_localizeStrings.Get(13106).c_str(), PVR_ADDON_NAME_STRING_LENGTH - 1);
101 void CPVRGUIInfo::Start(void)
108 void CPVRGUIInfo::Stop(void)
112 g_PVRTimers->UnregisterObserver(this);
115 void CPVRGUIInfo::Notify(const Observable &obs, const ObservableMessage msg)
117 if (msg == ObservableMessageTimers || msg == ObservableMessageTimersReset)
121 void CPVRGUIInfo::ShowPlayerInfo(int iTimeout)
123 CSingleLock lock(m_critSection);
126 m_ToggleShowInfo.Set(iTimeout * 1000);
128 g_infoManager.SetShowInfo(true);
131 void CPVRGUIInfo::ToggleShowInfo(void)
133 CSingleLock lock(m_critSection);
135 if (m_ToggleShowInfo.IsTimePast())
137 m_ToggleShowInfo.SetInfinite();
138 g_infoManager.SetShowInfo(false);
142 bool CPVRGUIInfo::AddonInfoToggle(void)
144 CSingleLock lock(m_critSection);
145 if (m_iAddonInfoToggleStart == 0)
147 m_iAddonInfoToggleStart = XbmcThreads::SystemClockMillis();
148 m_iAddonInfoToggleCurrent = 0;
152 if ((int) (XbmcThreads::SystemClockMillis() - m_iAddonInfoToggleStart) > g_advancedSettings.m_iPVRInfoToggleInterval)
154 unsigned int iPrevious = m_iAddonInfoToggleCurrent;
155 if (((int) ++m_iAddonInfoToggleCurrent) > m_iActiveClients - 1)
156 m_iAddonInfoToggleCurrent = 0;
158 return m_iAddonInfoToggleCurrent != iPrevious;
164 bool CPVRGUIInfo::TimerInfoToggle(void)
166 CSingleLock lock(m_critSection);
167 if (m_iTimerInfoToggleStart == 0)
169 m_iTimerInfoToggleStart = XbmcThreads::SystemClockMillis();
170 m_iTimerInfoToggleCurrent = 0;
174 if ((int) (XbmcThreads::SystemClockMillis() - m_iTimerInfoToggleStart) > g_advancedSettings.m_iPVRInfoToggleInterval)
176 unsigned int iPrevious = m_iTimerInfoToggleCurrent;
177 unsigned int iBoundary = m_iRecordingTimerAmount > 0 ? m_iRecordingTimerAmount : m_iTimerAmount;
178 if (++m_iTimerInfoToggleCurrent > iBoundary - 1)
179 m_iTimerInfoToggleCurrent = 0;
181 return m_iTimerInfoToggleCurrent != iPrevious;
187 void CPVRGUIInfo::Process(void)
189 unsigned int mLoop(0);
191 /* updated on request */
192 g_PVRTimers->RegisterObserver(this);
195 while (!g_application.m_bStop && !m_bStop)
214 UpdateTimersToggle();
221 if (!m_bStop && mLoop % 10 == 0)
222 UpdateBackendCache(); /* updated every 10 iterations */
235 void CPVRGUIInfo::UpdateQualityData(void)
237 PVR_SIGNAL_STATUS qualityInfo;
238 ClearQualityInfo(qualityInfo);
241 if (CSettings::Get().GetBool("pvrplayback.signalquality") &&
242 g_PVRClients->GetPlayingClient(client))
244 client->SignalQuality(qualityInfo);
247 memcpy(&m_qualityInfo, &qualityInfo, sizeof(m_qualityInfo));
250 void CPVRGUIInfo::UpdateMisc(void)
252 bool bStarted = g_PVRManager.IsStarted();
253 CStdString strPlayingClientName = bStarted ? g_PVRClients->GetPlayingClientName() : StringUtils::EmptyString;
254 bool bHasRecordings = bStarted && g_PVRRecordings->GetNumRecordings() > 0;
255 bool bIsPlayingTV = bStarted && g_PVRClients->IsPlayingTV();
256 bool bIsPlayingRadio = bStarted && g_PVRClients->IsPlayingRadio();
257 bool bIsPlayingRecording = bStarted && g_PVRClients->IsPlayingRecording();
258 bool bIsPlayingEncryptedStream = bStarted && g_PVRClients->IsEncrypted();
259 /* safe to fetch these unlocked, since they're updated from the same thread as this one */
260 bool bHasNonRecordingTimers = bStarted && m_iTimerAmount - m_iRecordingTimerAmount > 0;
262 CSingleLock lock(m_critSection);
263 m_strPlayingClientName = strPlayingClientName;
264 m_bHasRecordings = bHasRecordings;
265 m_bHasNonRecordingTimers = bHasNonRecordingTimers;
266 m_bIsPlayingTV = bIsPlayingTV;
267 m_bIsPlayingRadio = bIsPlayingRadio;
268 m_bIsPlayingRecording = bIsPlayingRecording;
269 m_bIsPlayingEncryptedStream = bIsPlayingEncryptedStream;
272 bool CPVRGUIInfo::TranslateCharInfo(DWORD dwInfo, CStdString &strValue) const
275 CSingleLock lock(m_critSection);
279 case PVR_NOW_RECORDING_TITLE:
280 CharInfoActiveTimerTitle(strValue);
282 case PVR_NOW_RECORDING_CHANNEL:
283 CharInfoActiveTimerChannelName(strValue);
285 case PVR_NOW_RECORDING_CHAN_ICO:
286 CharInfoActiveTimerChannelIcon(strValue);
288 case PVR_NOW_RECORDING_DATETIME:
289 CharInfoActiveTimerDateTime(strValue);
291 case PVR_NEXT_RECORDING_TITLE:
292 CharInfoNextTimerTitle(strValue);
294 case PVR_NEXT_RECORDING_CHANNEL:
295 CharInfoNextTimerChannelName(strValue);
297 case PVR_NEXT_RECORDING_CHAN_ICO:
298 CharInfoNextTimerChannelIcon(strValue);
300 case PVR_NEXT_RECORDING_DATETIME:
301 CharInfoNextTimerDateTime(strValue);
303 case PVR_PLAYING_DURATION:
304 CharInfoPlayingDuration(strValue);
306 case PVR_PLAYING_TIME:
307 CharInfoPlayingTime(strValue);
310 CharInfoNextTimer(strValue);
312 case PVR_ACTUAL_STREAM_VIDEO_BR:
313 CharInfoVideoBR(strValue);
315 case PVR_ACTUAL_STREAM_AUDIO_BR:
316 CharInfoAudioBR(strValue);
318 case PVR_ACTUAL_STREAM_DOLBY_BR:
319 CharInfoDolbyBR(strValue);
321 case PVR_ACTUAL_STREAM_SIG:
322 CharInfoSignal(strValue);
324 case PVR_ACTUAL_STREAM_SNR:
325 CharInfoSNR(strValue);
327 case PVR_ACTUAL_STREAM_BER:
328 CharInfoBER(strValue);
330 case PVR_ACTUAL_STREAM_UNC:
331 CharInfoUNC(strValue);
333 case PVR_ACTUAL_STREAM_CLIENT:
334 CharInfoPlayingClientName(strValue);
336 case PVR_ACTUAL_STREAM_DEVICE:
337 CharInfoFrontendName(strValue);
339 case PVR_ACTUAL_STREAM_STATUS:
340 CharInfoFrontendStatus(strValue);
342 case PVR_ACTUAL_STREAM_CRYPTION:
343 CharInfoEncryption(strValue);
345 case PVR_ACTUAL_STREAM_SERVICE:
346 CharInfoService(strValue);
348 case PVR_ACTUAL_STREAM_MUX:
349 CharInfoMux(strValue);
351 case PVR_ACTUAL_STREAM_PROVIDER:
352 CharInfoProvider(strValue);
354 case PVR_BACKEND_NAME:
355 CharInfoBackendName(strValue);
357 case PVR_BACKEND_VERSION:
358 CharInfoBackendVersion(strValue);
360 case PVR_BACKEND_HOST:
361 CharInfoBackendHost(strValue);
363 case PVR_BACKEND_DISKSPACE:
364 CharInfoBackendDiskspace(strValue);
366 case PVR_BACKEND_CHANNELS:
367 CharInfoBackendChannels(strValue);
369 case PVR_BACKEND_TIMERS:
370 CharInfoBackendTimers(strValue);
372 case PVR_BACKEND_RECORDINGS:
373 CharInfoBackendRecordings(strValue);
375 case PVR_BACKEND_NUMBER:
376 CharInfoBackendNumber(strValue);
378 case PVR_TOTAL_DISKSPACE:
379 CharInfoTotalDiskSpace(strValue);
382 strValue = StringUtils::EmptyString;
390 bool CPVRGUIInfo::TranslateBoolInfo(DWORD dwInfo) const
393 CSingleLock lock(m_critSection);
397 case PVR_IS_RECORDING:
398 bReturn = m_iRecordingTimerAmount > 0;
401 bReturn = m_iTimerAmount > 0;
403 case PVR_HAS_NONRECORDING_TIMER:
404 bReturn = m_bHasNonRecordingTimers;
406 case PVR_IS_PLAYING_TV:
407 bReturn = m_bIsPlayingTV;
409 case PVR_IS_PLAYING_RADIO:
410 bReturn = m_bIsPlayingRadio;
412 case PVR_IS_PLAYING_RECORDING:
413 bReturn = m_bIsPlayingRecording;
415 case PVR_ACTUAL_STREAM_ENCRYPTED:
416 bReturn = m_bIsPlayingEncryptedStream;
425 int CPVRGUIInfo::TranslateIntInfo(DWORD dwInfo) const
428 CSingleLock lock(m_critSection);
430 if (dwInfo == PVR_PLAYING_PROGRESS)
431 iReturn = (int) ((float) GetStartTime() / m_iDuration * 100);
432 else if (dwInfo == PVR_ACTUAL_STREAM_SIG_PROGR)
433 iReturn = (int) ((float) m_qualityInfo.iSignal / 0xFFFF * 100);
434 else if (dwInfo == PVR_ACTUAL_STREAM_SNR_PROGR)
435 iReturn = (int) ((float) m_qualityInfo.iSNR / 0xFFFF * 100);
440 void CPVRGUIInfo::CharInfoActiveTimerTitle(CStdString &strValue) const
442 strValue = StringUtils::Format("%s", m_strActiveTimerTitle.c_str());
445 void CPVRGUIInfo::CharInfoActiveTimerChannelName(CStdString &strValue) const
447 strValue = StringUtils::Format("%s", m_strActiveTimerChannelName.c_str());
450 void CPVRGUIInfo::CharInfoActiveTimerChannelIcon(CStdString &strValue) const
452 strValue = StringUtils::Format("%s", m_strActiveTimerChannelIcon.c_str());
455 void CPVRGUIInfo::CharInfoActiveTimerDateTime(CStdString &strValue) const
457 strValue = StringUtils::Format("%s", m_strActiveTimerTime.c_str());
460 void CPVRGUIInfo::CharInfoNextTimerTitle(CStdString &strValue) const
462 strValue = StringUtils::Format("%s", m_strNextRecordingTitle.c_str());
465 void CPVRGUIInfo::CharInfoNextTimerChannelName(CStdString &strValue) const
467 strValue = StringUtils::Format("%s", m_strNextRecordingChannelName.c_str());
470 void CPVRGUIInfo::CharInfoNextTimerChannelIcon(CStdString &strValue) const
472 strValue = StringUtils::Format("%s", m_strNextRecordingChannelIcon.c_str());
475 void CPVRGUIInfo::CharInfoNextTimerDateTime(CStdString &strValue) const
477 strValue = StringUtils::Format("%s", m_strNextRecordingTime.c_str());
480 void CPVRGUIInfo::CharInfoPlayingDuration(CStdString &strValue) const
482 strValue = StringUtils::Format("%s", StringUtils::SecondsToTimeString(m_iDuration / 1000, TIME_FORMAT_GUESS).c_str());
485 void CPVRGUIInfo::CharInfoPlayingTime(CStdString &strValue) const
487 strValue = StringUtils::Format("%s", StringUtils::SecondsToTimeString(GetStartTime()/1000, TIME_FORMAT_GUESS).c_str());
490 void CPVRGUIInfo::CharInfoNextTimer(CStdString &strValue) const
492 strValue = StringUtils::Format("%s", m_strNextTimerInfo.c_str());
495 void CPVRGUIInfo::CharInfoBackendNumber(CStdString &strValue) const
497 if (m_iActiveClients > 0)
498 strValue = StringUtils::Format("%u %s %u", m_iAddonInfoToggleCurrent+1, g_localizeStrings.Get(20163).c_str(), m_iActiveClients);
500 strValue = StringUtils::Format("%s", g_localizeStrings.Get(14023).c_str());
503 void CPVRGUIInfo::CharInfoTotalDiskSpace(CStdString &strValue) const
505 strValue = StringUtils::Format("%s", m_strTotalDiskspace.c_str());
508 void CPVRGUIInfo::CharInfoVideoBR(CStdString &strValue) const
510 strValue = StringUtils::Format("%.2f Mbit/s", m_qualityInfo.dVideoBitrate);
513 void CPVRGUIInfo::CharInfoAudioBR(CStdString &strValue) const
515 strValue = StringUtils::Format("%.0f kbit/s", m_qualityInfo.dAudioBitrate);
518 void CPVRGUIInfo::CharInfoDolbyBR(CStdString &strValue) const
520 strValue = StringUtils::Format("%.0f kbit/s", m_qualityInfo.dDolbyBitrate);
523 void CPVRGUIInfo::CharInfoSignal(CStdString &strValue) const
525 strValue = StringUtils::Format("%d %%", m_qualityInfo.iSignal / 655);
528 void CPVRGUIInfo::CharInfoSNR(CStdString &strValue) const
530 strValue = StringUtils::Format("%d %%", m_qualityInfo.iSNR / 655);
533 void CPVRGUIInfo::CharInfoBER(CStdString &strValue) const
535 strValue = StringUtils::Format("%08X", m_qualityInfo.iBER);
538 void CPVRGUIInfo::CharInfoUNC(CStdString &strValue) const
540 strValue = StringUtils::Format("%08X", m_qualityInfo.iUNC);
543 void CPVRGUIInfo::CharInfoFrontendName(CStdString &strValue) const
545 if (!strcmp(m_qualityInfo.strAdapterName, StringUtils::EmptyString))
546 strValue = StringUtils::Format("%s", g_localizeStrings.Get(13205).c_str());
548 strValue = StringUtils::Format("%s", m_qualityInfo.strAdapterName);
551 void CPVRGUIInfo::CharInfoFrontendStatus(CStdString &strValue) const
553 if (!strcmp(m_qualityInfo.strAdapterStatus, StringUtils::EmptyString))
554 strValue = StringUtils::Format("%s", g_localizeStrings.Get(13205).c_str());
556 strValue = StringUtils::Format("%s", m_qualityInfo.strAdapterStatus);
559 void CPVRGUIInfo::CharInfoBackendName(CStdString &strValue) const
561 if (m_strBackendName.IsEmpty())
562 strValue = StringUtils::Format("%s", g_localizeStrings.Get(13205).c_str());
564 strValue = StringUtils::Format("%s", m_strBackendName.c_str());
567 void CPVRGUIInfo::CharInfoBackendVersion(CStdString &strValue) const
569 if (m_strBackendVersion.IsEmpty())
570 strValue = StringUtils::Format("%s", g_localizeStrings.Get(13205).c_str());
572 strValue = StringUtils::Format("%s", m_strBackendVersion.c_str());
575 void CPVRGUIInfo::CharInfoBackendHost(CStdString &strValue) const
577 if (m_strBackendHost.IsEmpty())
578 strValue = StringUtils::Format("%s", g_localizeStrings.Get(13205).c_str());
580 strValue = StringUtils::Format("%s", m_strBackendHost.c_str());
583 void CPVRGUIInfo::CharInfoBackendDiskspace(CStdString &strValue) const
585 if (m_strBackendDiskspace.IsEmpty())
586 strValue = StringUtils::Format("%s", g_localizeStrings.Get(13205).c_str());
588 strValue = StringUtils::Format("%s", m_strBackendDiskspace.c_str());
591 void CPVRGUIInfo::CharInfoBackendChannels(CStdString &strValue) const
593 if (m_strBackendChannels.IsEmpty())
594 strValue = StringUtils::Format("%s", g_localizeStrings.Get(13205).c_str());
596 strValue = StringUtils::Format("%s", m_strBackendChannels.c_str());
599 void CPVRGUIInfo::CharInfoBackendTimers(CStdString &strValue) const
601 if (m_strBackendTimers.IsEmpty())
602 strValue = StringUtils::Format("%s", g_localizeStrings.Get(13205).c_str());
604 strValue = StringUtils::Format("%s", m_strBackendTimers.c_str());
607 void CPVRGUIInfo::CharInfoBackendRecordings(CStdString &strValue) const
609 if (m_strBackendRecordings.IsEmpty())
610 strValue = StringUtils::Format("%s", g_localizeStrings.Get(13205).c_str());
612 strValue = StringUtils::Format("%s", m_strBackendRecordings.c_str());
615 void CPVRGUIInfo::CharInfoPlayingClientName(CStdString &strValue) const
617 if (m_strPlayingClientName.IsEmpty())
618 strValue = StringUtils::Format("%s", g_localizeStrings.Get(13205).c_str());
620 strValue = StringUtils::Format("%s", m_strPlayingClientName.c_str());
623 void CPVRGUIInfo::CharInfoEncryption(CStdString &strValue) const
625 CPVRChannelPtr channel;
626 if (g_PVRClients->GetPlayingChannel(channel))
627 strValue = StringUtils::Format("%s", channel->EncryptionName().c_str());
629 strValue = StringUtils::EmptyString;
632 void CPVRGUIInfo::CharInfoService(CStdString &strValue) const
634 if (!strcmp(m_qualityInfo.strServiceName, StringUtils::EmptyString))
635 strValue = StringUtils::Format("%s", g_localizeStrings.Get(13205).c_str());
637 strValue = StringUtils::Format("%s", m_qualityInfo.strServiceName);
640 void CPVRGUIInfo::CharInfoMux(CStdString &strValue) const
642 if (!strcmp(m_qualityInfo.strMuxName, StringUtils::EmptyString))
643 strValue = StringUtils::Format("%s", g_localizeStrings.Get(13205).c_str());
645 strValue = StringUtils::Format("%s", m_qualityInfo.strMuxName);
648 void CPVRGUIInfo::CharInfoProvider(CStdString &strValue) const
650 if (!strcmp(m_qualityInfo.strProviderName, StringUtils::EmptyString))
651 strValue = StringUtils::Format("%s", g_localizeStrings.Get(13205).c_str());
653 strValue = StringUtils::Format("%s", m_qualityInfo.strProviderName);
656 void CPVRGUIInfo::UpdateBackendCache(void)
658 CStdString strBackendName;
659 CStdString strBackendVersion;
660 CStdString strBackendHost;
661 CStdString strBackendDiskspace;
662 CStdString strBackendTimers;
663 CStdString strBackendRecordings;
664 CStdString strBackendChannels;
665 int iActiveClients(0);
667 if (!AddonInfoToggle())
670 CPVRClients *clients = g_PVRClients;
671 PVR_CLIENTMAP activeClients;
672 iActiveClients = clients->GetConnectedClients(activeClients);
673 if (iActiveClients > 0)
675 PVR_CLIENTMAP_CITR activeClient = activeClients.begin();
676 /* safe to read unlocked */
677 for (unsigned int i = 0; i < m_iAddonInfoToggleCurrent; i++)
680 long long kBTotal = 0;
681 long long kBUsed = 0;
683 if (activeClient->second->GetDriveSpace(&kBTotal, &kBUsed) == PVR_ERROR_NO_ERROR)
685 kBTotal /= 1024; // Convert to MBytes
686 kBUsed /= 1024; // Convert to MBytes
687 strBackendDiskspace = StringUtils::Format("%s %.1f GByte - %s: %.1f GByte",
688 g_localizeStrings.Get(20161).c_str(), (float) kBTotal / 1024, g_localizeStrings.Get(20162).c_str(), (float) kBUsed / 1024);
692 strBackendDiskspace = g_localizeStrings.Get(19055);
695 int NumChannels = activeClient->second->GetChannelsAmount();
696 if (NumChannels >= 0)
697 strBackendChannels = StringUtils::Format("%i", NumChannels);
699 strBackendChannels = g_localizeStrings.Get(161);
701 int NumTimers = activeClient->second->GetTimersAmount();
703 strBackendTimers = StringUtils::Format("%i", NumTimers);
705 strBackendTimers = g_localizeStrings.Get(161);
707 int NumRecordings = activeClient->second->GetRecordingsAmount();
708 if (NumRecordings >= 0)
709 strBackendRecordings = StringUtils::Format("%i", NumRecordings);
711 strBackendRecordings = g_localizeStrings.Get(161);
713 strBackendName = activeClient->second->GetBackendName();
714 strBackendVersion = activeClient->second->GetBackendVersion();
715 strBackendHost = activeClient->second->GetConnectionString();
718 CSingleLock lock(m_critSection);
719 m_strBackendName = strBackendName;
720 m_strBackendVersion = strBackendVersion;
721 m_strBackendHost = strBackendHost;
722 m_strBackendDiskspace = strBackendDiskspace;
723 m_strBackendTimers = strBackendTimers;
724 m_strBackendRecordings = strBackendRecordings;
725 m_strBackendChannels = strBackendChannels;
726 m_iActiveClients = iActiveClients;
729 void CPVRGUIInfo::UpdateTimersCache(void)
731 int iTimerAmount = g_PVRTimers->AmountActiveTimers();
732 int iRecordingTimerAmount = g_PVRTimers->AmountActiveRecordings();
735 CSingleLock lock(m_critSection);
736 m_iTimerAmount = iTimerAmount;
737 m_iRecordingTimerAmount = iRecordingTimerAmount;
738 m_iTimerInfoToggleStart = 0;
741 UpdateTimersToggle();
744 void CPVRGUIInfo::UpdateNextTimer(void)
746 CStdString strNextRecordingTitle;
747 CStdString strNextRecordingChannelName;
748 CStdString strNextRecordingChannelIcon;
749 CStdString strNextRecordingTime;
750 CStdString strNextTimerInfo;
752 CFileItemPtr tag = g_PVRTimers->GetNextActiveTimer();
753 if (tag && tag->HasPVRTimerInfoTag())
755 CPVRTimerInfoTag *timer = tag->GetPVRTimerInfoTag();
756 strNextRecordingTitle = StringUtils::Format("%s", timer->Title().c_str());
757 strNextRecordingChannelName = StringUtils::Format("%s", timer->ChannelName().c_str());
758 strNextRecordingChannelIcon = StringUtils::Format("%s", timer->ChannelIcon().c_str());
759 strNextRecordingTime = StringUtils::Format("%s", timer->StartAsLocalTime().GetAsLocalizedDateTime(false, false).c_str());
761 strNextTimerInfo = StringUtils::Format("%s %s %s %s",
762 g_localizeStrings.Get(19106).c_str(),
763 timer->StartAsLocalTime().GetAsLocalizedDate(true).c_str(),
764 g_localizeStrings.Get(19107).c_str(),
765 timer->StartAsLocalTime().GetAsLocalizedTime("HH:mm", false).c_str());
768 CSingleLock lock(m_critSection);
769 m_strNextRecordingTitle = strNextRecordingTitle;
770 m_strNextRecordingChannelName = strNextRecordingChannelName;
771 m_strNextRecordingChannelIcon = strNextRecordingChannelIcon;
772 m_strNextRecordingTime = strNextRecordingTime;
773 m_strNextTimerInfo = strNextTimerInfo;
776 void CPVRGUIInfo::UpdateTimersToggle(void)
778 if (!TimerInfoToggle())
781 CStdString strActiveTimerTitle;
782 CStdString strActiveTimerChannelName;
783 CStdString strActiveTimerChannelIcon;
784 CStdString strActiveTimerTime;
786 /* safe to fetch these unlocked, since they're updated from the same thread as this one */
787 if (m_iRecordingTimerAmount > 0)
789 vector<CFileItemPtr> activeTags = g_PVRTimers->GetActiveRecordings();
790 if (m_iTimerInfoToggleCurrent < activeTags.size() && activeTags.at(m_iTimerInfoToggleCurrent)->HasPVRTimerInfoTag())
792 CPVRTimerInfoTag *tag = activeTags.at(m_iTimerInfoToggleCurrent)->GetPVRTimerInfoTag();
793 strActiveTimerTitle = StringUtils::Format("%s", tag->Title().c_str());
794 strActiveTimerChannelName = StringUtils::Format("%s", tag->ChannelName().c_str());
795 strActiveTimerChannelIcon = StringUtils::Format("%s", tag->ChannelIcon().c_str());
796 strActiveTimerTime = StringUtils::Format("%s", tag->StartAsLocalTime().GetAsLocalizedDateTime(false, false).c_str());
800 CSingleLock lock(m_critSection);
801 m_strActiveTimerTitle = strActiveTimerTitle;
802 m_strActiveTimerChannelName = strActiveTimerChannelName;
803 m_strActiveTimerChannelIcon = strActiveTimerChannelIcon;
804 m_strActiveTimerTime = strActiveTimerTime;
807 int CPVRGUIInfo::GetDuration(void) const
809 CSingleLock lock(m_critSection);
813 int CPVRGUIInfo::GetStartTime(void) const
815 CSingleLock lock(m_critSection);
818 /* Calculate here the position we have of the running live TV event.
819 * "position in ms" = ("current UTC" - "event start UTC") * 1000
821 CDateTime current = g_PVRClients->GetPlayingTime();
822 CDateTime start = m_playingEpgTag->StartAsUTC();
823 CDateTimeSpan time = current > start ? current - start : CDateTimeSpan(0, 0, 0, 0);
824 return (time.GetDays() * 60 * 60 * 24
825 + time.GetHours() * 60 * 60
826 + time.GetMinutes() * 60
827 + time.GetSeconds()) * 1000;
835 void CPVRGUIInfo::ResetPlayingTag(void)
837 CSingleLock lock(m_critSection);
838 SAFE_DELETE(m_playingEpgTag);
842 bool CPVRGUIInfo::GetPlayingTag(CEpgInfoTag &tag) const
846 CSingleLock lock(m_critSection);
849 tag = *m_playingEpgTag;
856 void CPVRGUIInfo::UpdatePlayingTag(void)
858 CPVRChannelPtr currentChannel;
859 CPVRRecording recording;
860 if (g_PVRManager.GetCurrentChannel(currentChannel))
863 bool bHasEpgTag = GetPlayingTag(epgTag);
864 CPVRChannelPtr channel;
866 channel = epgTag.ChannelTag();
868 if (!bHasEpgTag || !epgTag.IsActive() ||
869 !channel || *channel != *currentChannel)
873 CSingleLock lock(m_critSection);
875 if (currentChannel->GetEPGNow(newTag))
877 m_playingEpgTag = new CEpgInfoTag(newTag);
878 m_iDuration = m_playingEpgTag->GetDuration() * 1000;
881 g_PVRManager.UpdateCurrentFile();
884 else if (g_PVRClients->GetPlayingRecording(recording))
887 m_iDuration = recording.GetDuration() * 1000;