Пример #1
0
    /// <summary>
    /// Tries to find an existing control for given <paramref name="program"/> in the Grid row with index <paramref name="rowIndex"/>.
    /// If no control was found, this method creates a new control and adds it to the Grid.
    /// </summary>
    /// <param name="program">Program.</param>
    /// <param name="rowIndex">RowIndex.</param>
    /// <returns>Control.</returns>
    private Control GetOrCreateControl(ProgramListItem program, int rowIndex)
    {
      Control control = GetRowItems(rowIndex).FirstOrDefault(el => ((ProgramListItem)el.Context).Program.ProgramId == program.Program.ProgramId);
      if (control != null)
        return control;

      control = CreateControl(program);
      // Deep copy the styles to each program button.
      control.Template = MpfCopyManager.DeepCopyCutLVPs(ProgramTemplate);
      Children.Add(control);
      return control;
    }
    private ProgramListItem BuildProgramListItem(IProgram program)
    {
      ProgramProperties programProperties = new ProgramProperties();
      IProgram currentProgram = program;
      programProperties.SetProgram(currentProgram);

      ProgramListItem item = new ProgramListItem(programProperties)
        {
          Command = new MethodDelegateCommand(() => ShowProgramActions(currentProgram))
        };
      item.AdditionalProperties["PROGRAM"] = currentProgram;
      return item;
    }
Пример #3
0
    /// <summary>
    /// Calculates to position (Column) and size (ColumnSpan) for the given <paramref name="program"/> by considering the avaiable viewport (<paramref name="viewportStart"/>, <paramref name="viewportEnd"/>).
    /// </summary>
    /// <param name="program">Program.</param>
    /// <param name="viewportStart">Viewport from.</param>
    /// <param name="viewportEnd">Viewport to.</param>
    /// <param name="colIndex">Returns Column.</param>
    /// <param name="colSpan">Returns ColumnSpan.</param>
    /// <param name="lastEndTime">Last program's end time.</param>
    private void CalculateProgamPosition(ProgramListItem program, DateTime viewportStart, DateTime viewportEnd, ref int colIndex, ref int colSpan, ref DateTime? lastEndTime)
    {
      if (program.Program.EndTime < viewportStart || program.Program.StartTime > viewportEnd)
        return;

      DateTime programViewStart = program.Program.StartTime < viewportStart ? viewportStart : program.Program.StartTime;

      double minutesSinceStart = (programViewStart - viewportStart).TotalMinutes;
      if (lastEndTime != null)
      {
        int newColIndex = (int)Math.Round(minutesSinceStart / _perCellTime) + 1; // Header offset
        if (lastEndTime != program.Program.StartTime)
          colIndex = Math.Max(colIndex, newColIndex); // colIndex is already set to new position. Calculation is only done to support gaps in programs.

        lastEndTime = program.Program.EndTime;
      }

      colSpan = (int)Math.Round((program.Program.EndTime - programViewStart).TotalMinutes / _perCellTime);

      if (colIndex + colSpan > _numberOfColumns + 1)
        colSpan = _numberOfColumns - colIndex + 1;

      if (colSpan == 0)
        colSpan = 1;

#if DEBUG_LAYOUT
        // Debug layouting:
      ServiceRegistration.Get<ILogger>().Debug("EPG: {0,2}-{1,2}: {3}-{4}: {2}", colIndex, colSpan, program.Program.Title, program.Program.StartTime.ToShortTimeString(), program.Program.EndTime.ToShortTimeString());
#endif
    }
    protected override void UpdatePrograms()
    {
      _programsList.Clear();
      if (_channel != null)
      {
        if (_tvHandler.ProgramInfo.GetPrograms(_channel, DateTime.Now.AddHours(-2), DateTime.Now.AddHours(24), out _programs))
        {
          foreach (IProgram program in _programs)
          {
            // Use local variable, otherwise delegate argument is not fixed
            ProgramProperties programProperties = new ProgramProperties();
            IProgram currentProgram = program;
            programProperties.SetProgram(currentProgram);

            ProgramListItem item = new ProgramListItem(programProperties)
                              {
                                Command = new MethodDelegateCommand(() => ShowProgramActions(currentProgram))
                              };
            item.AdditionalProperties["PROGRAM"] = currentProgram;

            _programsList.Add(item);
          }
        }
        ProgramsList.FireChange();
      }
      else
        _programs = null;
    }
    private void FillProgramsList()
    {
      _programsList.Clear();

      foreach (IProgram program in _programs)
      {
        // Use local variable, otherwise delegate argument is not fixed
        ProgramProperties programProperties = new ProgramProperties();
        IProgram currentProgram = program;
        programProperties.SetProgram(currentProgram);

        if (ProgramComparer.Instance.Equals(currentProgram, program))
        {
        }

        ProgramListItem item = new ProgramListItem(programProperties)
        {
          Command = new MethodDelegateCommand(() =>
          {
            var isSingle = programProperties.IsScheduled;
            var isSeries = programProperties.IsSeriesScheduled;
            if (isSingle || isSeries)
              CancelSchedule(currentProgram);
            else
              RecordSeries(currentProgram);
          })
        };
        item.AdditionalProperties["PROGRAM"] = currentProgram;
        item.Selected = _lastProgramId == program.ProgramId; // Restore focus

        _programsList.Add(item);
      }

      _programsList.FireChange();
    }
    private ListItem CreateProgramItem(IProgram program, ISchedule schedule)
    {
      ProgramProperties programProperties = new ProgramProperties();
      IProgram currentProgram = program;
      programProperties.SetProgram(currentProgram);

      ListItem item = new ProgramListItem(programProperties)
      {
        Command = new MethodDelegateCommand(() => ShowActions(schedule, program))
      };
      IChannel channel;
      if (_tvHandler.ChannelAndGroupInfo.GetChannel(currentProgram.ChannelId, out channel))
        item.SetLabel("ChannelName", channel.Name);
      item.SetLabel("ScheduleType", string.Format("[SlimTvClient.ScheduleRecordingType_{0}]", schedule.RecordingType));
      item.AdditionalProperties["PROGRAM"] = currentProgram;
      item.AdditionalProperties["SCHEDULE"] = schedule;
      return item;
    }
    private void FillProgramsList()
    {
      _programsList.Clear();

      bool isSingle = false;
      bool isSeries = false;
      foreach (IProgram program in _programs)
      {
        // Use local variable, otherwise delegate argument is not fixed
        ProgramProperties programProperties = new ProgramProperties();
        IProgram currentProgram = program;
        programProperties.SetProgram(currentProgram);

        if (ProgramComparer.Instance.Equals(_selectedProgram, program))
        {
          isSingle = programProperties.IsScheduled;
          isSeries = programProperties.IsSeriesScheduled;
        }

        ProgramListItem item = new ProgramListItem(programProperties)
        {
          Command = new MethodDelegateCommand(() => CreateOrDeleteSchedule(currentProgram))
        };
        item.AdditionalProperties["PROGRAM"] = currentProgram;
        item.Selected = _lastProgramId == program.ProgramId; // Restore focus

        _programsList.Add(item);
      }

      // "Record" buttons are related to properties, for schedules we need to keep them to "Cancel record" state.
      if (_isScheduleMode)
        isSingle = isSeries = _selectedSchedule != null;

      IsSingleRecordingScheduled = isSingle;
      IsSeriesRecordingScheduled = isSeries;

      _programsList.FireChange();
    }
Пример #8
0
    /// <summary>
    /// Gets the currently focused program or header control and its Grid.Row.
    /// </summary>
    /// <param name="program">Focused program</param>
    /// <param name="headerControl">Focused header</param>
    /// <param name="row">The focused row</param>
    /// <returns><c>true</c> if matching program could be found</returns>
    private bool GetFocusedRowAndStartTime(out ProgramListItem program, out FrameworkElement headerControl, out int row)
    {
      program = null;
      headerControl = null;
      row = 0;
      FrameworkElement currentElement = GetFocusedElementOrChild();

      while (currentElement != null)
      {
        if (currentElement.DataContext != null)
        {
          // Check for program
          var item = currentElement.DataContext.Source as ProgramListItem;
          if (item != null)
          {
            program = item;
            row = GetRow(currentElement);
            return true;
          }
          // Check for channel header
          var channel = currentElement.DataContext.Source as ChannelProgramListItem;
          if (channel != null)
          {
            headerControl = currentElement;
            row = GetRow(currentElement);
            return true;
          }
        }
        currentElement = currentElement.LogicalParent as Control;
      }
      return false;
    }