Esempio n. 1
0
        private GUIListControl getChannelList()
        {
            GUIListControl lstChannels = null;

            if (TVHome.ShowChannelStateIcons() && lstChannelsWithStateIcons != null)
            {
                lstChannels = lstChannelsWithStateIcons;
            }
            else
            {
                lstChannels = lstChannelsNoStateIcons;
            }

            return(lstChannels);
        }
Esempio n. 2
0
        /// <summary>
        /// Fill the list with channels
        /// </summary>
        public void FillChannelList()
        {
            List <Channel> tvChannelList = GetChannelListByGroup();

            benchClock = Stopwatch.StartNew();

            DateTime nextEPGupdate = GetNextEpgUpdate();
            Dictionary <int, NowAndNext> listNowNext = GetNowAndNext(tvChannelList, nextEPGupdate);

            benchClock.Stop();
            Log.Debug("TvMiniGuide: FillChannelList retrieved {0} programs for {1} channels in {2} ms", listNowNext.Count,
                      tvChannelList.Count, benchClock.ElapsedMilliseconds.ToString());

            GUIListItem item        = null;
            string      ChannelLogo = "";
            //List<int> RecChannels = null;
            //List<int> TSChannels = null;
            int  SelectedID        = 0;
            int  channelID         = 0;
            bool DisplayStatusInfo = true;


            Dictionary <int, ChannelState> tvChannelStatesList = null;

            if (TVHome.ShowChannelStateIcons())
            {
                benchClock.Reset();
                benchClock.Start();

                if (TVHome.Navigator.CurrentGroup.GroupName.Equals(TvConstants.TvGroupNames.AllChannels) ||
                    (!g_Player.IsTV && !g_Player.Playing))
                {
                    //we have no way of using the cached channelstates on the server in the following situations.
                    // 1) when the "all channels" group is selected - too many channels.
                    // 2) when user is not timeshifting - no user object on the server.
                    User currentUser = new User();
                    tvChannelStatesList = TVHome.TvServer.GetAllChannelStatesForGroup(TVHome.Navigator.CurrentGroup.IdGroup,
                                                                                      currentUser);
                }
                else
                {
                    // use the more speedy approach
                    // ask the server of the cached list of channel states corresponding to the user.
                    tvChannelStatesList = TVHome.TvServer.GetAllChannelStatesCached(TVHome.Card.User);

                    if (tvChannelStatesList == null)
                    {
                        //slow approach.
                        tvChannelStatesList = TVHome.TvServer.GetAllChannelStatesForGroup(TVHome.Navigator.CurrentGroup.IdGroup,
                                                                                          TVHome.Card.User);
                    }
                }

                benchClock.Stop();
                if (tvChannelStatesList != null)
                {
                    Log.Debug("TvMiniGuide: FillChannelList - {0} channel states for group retrieved in {1} ms",
                              Convert.ToString(tvChannelStatesList.Count), benchClock.ElapsedMilliseconds.ToString());
                }
            }

            for (int i = 0; i < tvChannelList.Count; i++)
            {
                Channel CurrentChan = tvChannelList[i];

                if (CurrentChan.VisibleInGuide)
                {
                    ChannelState CurrentChanState = ChannelState.tunable;
                    channelID = CurrentChan.IdChannel;
                    if (TVHome.ShowChannelStateIcons())
                    {
                        if (!tvChannelStatesList.TryGetValue(channelID, out CurrentChanState))
                        {
                            CurrentChanState = ChannelState.tunable;
                        }
                    }

                    //StringBuilder sb = new StringBuilder();
                    sb.Length = 0;
                    item      = new GUIListItem("");
                    // store here as it is not needed right now - please beat me later..
                    item.TVTag = CurrentChan;

                    sb.Append(CurrentChan.DisplayName);
                    ChannelLogo = Utils.GetCoverArt(Thumbs.TVChannel, CurrentChan.DisplayName);

                    // if we are watching this channel mark it
                    if (TVHome.Navigator != null && TVHome.Navigator.Channel != null &&
                        TVHome.Navigator.Channel.IdChannel == channelID)
                    {
                        item.IsRemote = true;
                        SelectedID    = lstChannels.Count;
                    }

                    if (!string.IsNullOrEmpty(ChannelLogo))
                    {
                        item.IconImageBig = ChannelLogo;
                        item.IconImage    = ChannelLogo;
                    }
                    else
                    {
                        item.IconImageBig = string.Empty;
                        item.IconImage    = string.Empty;
                    }

                    if (DisplayStatusInfo)
                    {
                        bool showChannelStateIcons = (TVHome.ShowChannelStateIcons() && lstChannelsWithStateIcons != null);

                        switch (CurrentChanState)
                        {
                        case ChannelState.nottunable:
                            item.IsPlayed = true;
                            if (showChannelStateIcons)
                            {
                                item.PinImage = Thumbs.TvIsUnavailableIcon;
                            }
                            else
                            {
                                sb.Append(" ");
                                sb.Append(local1056);
                            }
                            break;

                        case ChannelState.timeshifting:
                            if (showChannelStateIcons)
                            {
                                item.PinImage = Thumbs.TvIsTimeshiftingIcon;
                            }
                            else
                            {
                                sb.Append(" ");
                                sb.Append(local1055);
                            }
                            break;

                        case ChannelState.recording:
                            if (showChannelStateIcons)
                            {
                                item.PinImage = Thumbs.TvIsRecordingIcon;
                            }
                            else
                            {
                                sb.Append(" ");
                                sb.Append(local1054);
                            }
                            break;

                        default:
                            item.IsPlayed = false;
                            if (showChannelStateIcons)
                            {
                                item.PinImage = Thumbs.TvIsAvailableIcon;
                            }
                            break;
                        }
                    }
                    //StringBuilder sbTmp = new StringBuilder();
                    sbTmp.Length = 0;

                    NowAndNext currentNowAndNext = null;
                    bool       hasNowNext        = listNowNext.TryGetValue(channelID, out currentNowAndNext);

                    if (hasNowNext)
                    {
                        if (!string.IsNullOrEmpty(currentNowAndNext.TitleNow))
                        {
                            TVUtil.TitleDisplay(sbTmp, currentNowAndNext.TitleNow, currentNowAndNext.EpisodeName,
                                                currentNowAndNext.SeriesNum,
                                                currentNowAndNext.EpisodeNum, currentNowAndNext.EpisodePart);
                        }
                        else
                        {
                            sbTmp.Append(local736);
                        }
                    }
                    else
                    {
                        sbTmp.Append(local736);
                    }

                    item.Label2 = sbTmp.ToString();
                    sbTmp.Insert(0, local789);
                    item.Label3 = sbTmp.ToString();

                    sbTmp.Length = 0;

                    if (_showChannelNumber == true)
                    {
                        sb.Append(" - ");
                        if (!_byIndex)
                        {
                            sb.Append(tvChannelList[i].ChannelNumber);
                        }
                        else
                        {
                            sb.Append(i + 1);
                        }
                    }

                    if (hasNowNext)
                    {
                        // if the "Now" DB entry is in the future we set MinValue intentionally to avoid wrong percentage calculations
                        DateTime startTime = currentNowAndNext.NowStartTime;
                        if (startTime != SqlDateTime.MinValue.Value)
                        {
                            DateTime endTime = currentNowAndNext.NowEndTime;
                            sb.Append(" - ");
                            sb.Append(
                                CalculateProgress(startTime, endTime).ToString());
                            sb.Append("%");

                            if (endTime < nextEPGupdate || nextEPGupdate == DateTime.MinValue)
                            {
                                nextEPGupdate = endTime;
                                SetNextEpgUpdate(endTime);
                            }
                        }
                    }



                    if (hasNowNext && listNowNext[channelID].IdProgramNext != -1)
                    {
                        TVUtil.TitleDisplay(sbTmp, currentNowAndNext.TitleNext, currentNowAndNext.EpisodeNameNext,
                                            currentNowAndNext.SeriesNumNext,
                                            currentNowAndNext.EpisodeNumNext,
                                            currentNowAndNext.EpisodePartNext);
                    }
                    else
                    {
                        sbTmp.Append(local736);
                    }

                    item.Label2 = sb.ToString();

                    sbTmp.Insert(0, local790);

                    item.Label = sbTmp.ToString();

                    lstChannels.Add(item);
                }
            }
            benchClock.Stop();
            Log.Debug("TvMiniGuide: State check + filling completed after {0} ms", benchClock.ElapsedMilliseconds.ToString());
            lstChannels.SelectedListItemIndex = SelectedID;

            if (lstChannels.GetID == 37)
            {
                GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SETFOCUS, GetID, 0, 37, 0, 0, null);
                OnMessage(msg);
            }

            sb.Length    = 0;
            sbTmp.Length = 0;
        }