Exemplo n.º 1
0
        private IMBotMessage DoCancelCommand(IMBotConversation conversation, IList <string> arguments, bool cancel)
        {
            if (arguments.Count == 0)
            {
                return(new IMBotMessage("Program number is missing.", IMBotMessage.ErrorColor));
            }

            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
            {
                UpcomingProgram upcomingRecording;
                IMBotMessage    result = FindUpcomingRecording(tvSchedulerAgent, conversation, arguments, out upcomingRecording);
                if (result == null)
                {
                    StringBuilder replyText = new StringBuilder();
                    if (cancel)
                    {
                        if (upcomingRecording.IsPartOfSeries)
                        {
                            tvSchedulerAgent.CancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId,
                                                                   upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime);
                            replyText.Append("Cancelled ");
                        }
                        else
                        {
                            tvSchedulerAgent.DeleteSchedule(upcomingRecording.ScheduleId);
                            replyText.Append("Deleted schedule for ");
                        }
                    }
                    else
                    {
                        tvSchedulerAgent.UncancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId,
                                                                 upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime);
                        replyText.Append("Uncancelled ");
                    }

                    Utility.AppendProgramDetails(replyText, upcomingRecording.Channel, upcomingRecording);
                    replyText.Append(".");

                    result = new IMBotMessage(replyText.ToString());
                }
                return(result);
            }
        }
Exemplo n.º 2
0
        private IMBotMessage DoDeleteScheduleCommand(IMBotConversation conversation, IList <string> arguments)
        {
            if (arguments.Count == 0)
            {
                return(new IMBotMessage("Program number is missing.", IMBotMessage.ErrorColor));
            }

            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
            {
                UpcomingProgram upcomingRecording;
                IMBotMessage    result = FindUpcomingRecording(tvSchedulerAgent, conversation, arguments, out upcomingRecording);
                if (result == null)
                {
                    StringBuilder replyText = new StringBuilder();
                    tvSchedulerAgent.DeleteSchedule(upcomingRecording.ScheduleId);
                    replyText.Append("Deleted schedule for ");
                    Utility.AppendProgramDetails(replyText, upcomingRecording.Channel, upcomingRecording);
                    replyText.Append(".");
                    result = new IMBotMessage(replyText.ToString());
                }
                return(result);
            }
        }
Exemplo n.º 3
0
        private IMBotMessage DoDeleteScheduleCommand(IMBotConversation conversation, IList<string> arguments)
        {
            if (arguments.Count == 0)
            {
                return new IMBotMessage("Program number is missing.", IMBotMessage.ErrorColor);
            }

            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
            {
                UpcomingProgram upcomingRecording;
                IMBotMessage result = FindUpcomingRecording(tvSchedulerAgent, conversation, arguments, out upcomingRecording);
                if (result == null)
                {
                    StringBuilder replyText = new StringBuilder();
                    tvSchedulerAgent.DeleteSchedule(upcomingRecording.ScheduleId);
                    replyText.Append("Deleted schedule for ");
                    Utility.AppendProgramDetails(replyText, upcomingRecording.Channel, upcomingRecording);
                    replyText.Append(".");
                    result = new IMBotMessage(replyText.ToString());
                }
                return result;
            }
        }
Exemplo n.º 4
0
        private IMBotMessage DoCancelCommand(IMBotConversation conversation, IList<string> arguments, bool cancel)
        {
            if (arguments.Count == 0)
            {
                return new IMBotMessage("Program number is missing.", IMBotMessage.ErrorColor);
            }

            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
            {
                UpcomingProgram upcomingRecording;
                IMBotMessage result = FindUpcomingRecording(tvSchedulerAgent, conversation, arguments, out upcomingRecording);
                if (result == null)
                {
                    StringBuilder replyText = new StringBuilder();
                    if (cancel)
                    {
                        if (upcomingRecording.IsPartOfSeries)
                        {
                            tvSchedulerAgent.CancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId,
                                upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime);
                            replyText.Append("Cancelled ");
                        }
                        else
                        {
                            tvSchedulerAgent.DeleteSchedule(upcomingRecording.ScheduleId);
                            replyText.Append("Deleted schedule for ");
                        }
                    }
                    else
                    {
                        tvSchedulerAgent.UncancelUpcomingProgram(upcomingRecording.ScheduleId, upcomingRecording.GuideProgramId,
                            upcomingRecording.Channel.ChannelId, upcomingRecording.StartTime);
                        replyText.Append("Uncancelled ");
                    }

                    Utility.AppendProgramDetails(replyText, upcomingRecording.Channel, upcomingRecording);
                    replyText.Append(".");

                    result = new IMBotMessage(replyText.ToString());
                }
                return result;
            }
        }
Exemplo n.º 5
0
        public override bool OnMessage(GUIMessage message)
        {
            _needToClearScreen = true;

            #region case GUI_MSG_RECORD

            if (message.Message == GUIMessage.MessageType.GUI_MSG_RECORD)
            {
                if (_isDialogVisible)
                {
                    return false;
                }

                Channel currentChannel = PluginMain.Navigator.CurrentChannel;
                GuideProgram currentProgram = PluginMain.GetCurrentProgram(ChannelType.Television);
                if (currentChannel != null)
                {
                    ActiveRecording activeRecording;
                    if (currentProgram == null
                        || !PluginMain.IsActiveRecording(currentChannel.ChannelId, currentProgram, out activeRecording))
                    {
                        PluginMain.IsChannelRecording(currentChannel.ChannelId, out activeRecording);
                    }
                    if (activeRecording != null)
                    {
                        _dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                        _dlgYesNo.SetHeading(1449); // stop recording
                        _dlgYesNo.SetLine(1, 1450); // are you sure to stop recording?
                        _dlgYesNo.SetLine(2, activeRecording.Program.Title);
                        _dialogYesNoVisible = true;
                        _dlgYesNo.DoModal(GetID);
                        _dialogYesNoVisible = false;

                        if (_dlgYesNo.IsConfirmed)
                        {
                            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
                            {
                                Schedule schedule = tvSchedulerAgent.GetScheduleById(activeRecording.Program.ScheduleId);
                                if (schedule != null)
                                {
                                    if (activeRecording.Program.IsPartOfSeries)
                                    {
                                        tvSchedulerAgent.CancelUpcomingProgram(schedule.ScheduleId,
                                            currentProgram == null ? null : (Guid?)currentProgram.GuideProgramId,
                                            currentChannel.ChannelId, activeRecording.Program.StartTime);
                                    }
                                    else
                                    {
                                        tvSchedulerAgent.DeleteSchedule(schedule.ScheduleId);
                                    }
                                    string text = String.Format("{0} {1}-{2}",
                                          activeRecording.Program.Title,
                                          activeRecording.Program.StartTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat),
                                          activeRecording.Program.StopTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat));
                                    ShowRecordingNotifyDialog(tvSchedulerAgent, currentChannel, text, TextId.RecordingStopped);
                                }
                            }
                        }
                    }
                    else
                    {
                        _dialogMenu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                        if (_dialogMenu != null)
                        {
                            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
                            {
                                _dialogMenu.Reset();
                                _dialogMenu.SetHeading(Utility.GetLocalizedText(TextId.Record));
                                if (currentProgram != null)
                                {
                                    _dialogMenu.Add(Utility.GetLocalizedText(TextId.CurrentProgram));
                                }
                                _dialogMenu.Add("15 " + Utility.GetLocalizedText(TextId.Minutes));
                                _dialogMenu.Add("30 " + Utility.GetLocalizedText(TextId.Minutes));
                                _dialogMenu.Add("1 " + Utility.GetLocalizedText(TextId.Hour));
                                _dialogMenu.Add("1 " + Utility.GetLocalizedText(TextId.Hour) + " 30 " + Utility.GetLocalizedText(TextId.Minutes));
                                _dialogMenu.Add("2 " + Utility.GetLocalizedText(TextId.Hours));
                                _bottomDialogMenuVisible = true;

                                _dialogMenu.DoModal(GetID);

                                _bottomDialogMenuVisible = false;

                                Schedule schedule = null;
                                string notifyText = String.Empty;

                                int selectedLabel = _dialogMenu.SelectedLabel;
                                if (currentProgram == null)
                                {
                                    selectedLabel++;
                                }
                                switch (selectedLabel)
                                {
                                    case 0:
                                        schedule = GuideController.CreateRecordOnceSchedule(tvSchedulerAgent,
                                            PluginMain.Navigator.CurrentChannel.ChannelType,
                                            PluginMain.Navigator.CurrentChannel.ChannelId, currentProgram.Title, currentProgram.SubTitle,
                                            currentProgram.EpisodeNumberDisplay, currentProgram.StartTime);
                                        notifyText = String.Format("{0} {1}-{2}",
                                              currentProgram.Title,
                                              currentProgram.StartTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat),
                                              currentProgram.StopTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat));
                                        break;

                                    case 1:
                                        schedule = CreateManualSchedule(currentChannel, 15, out notifyText);
                                        break;

                                    case 2:
                                        schedule = CreateManualSchedule(currentChannel, 30, out notifyText);
                                        break;

                                    case 3:
                                        schedule = CreateManualSchedule(currentChannel, 60, out notifyText);
                                        break;

                                    case 4:
                                        schedule = CreateManualSchedule(currentChannel, 90, out notifyText);
                                        break;

                                    case 5:
                                        schedule = CreateManualSchedule(currentChannel, 2 * 60, out notifyText);
                                        break;
                                }

                                if (schedule != null)
                                {
                                    tvSchedulerAgent.SaveSchedule(schedule);
                                    ShowRecordingNotifyDialog(tvSchedulerAgent, currentChannel, notifyText, TextId.RecordingStarted);
                                }
                            }
                        }
                    }
                }
                return true;
            }

            #endregion

            #region case GUI_MSG_RECORDER_ABOUT_TO_START_RECORDING

            if (message.Message == GUIMessage.MessageType.GUI_MSG_RECORDER_ABOUT_TO_START_RECORDING)
            {
                /*
                        TVRecording rec = message.Object as TVRecording;
                        if (rec == null) return true;
                        if (rec.Channel == Recorder.TVChannelName) return true;
                        if (!Recorder.NeedChannelSwitchForRecording(rec)) return true;

                        _messageBoxVisible = false;
                        _msnWindowVisible = false;     // msn related can be removed
                        GUIWindowManager.IsOsdVisible = false;
                        if (_zapOsdVisible)
                        {
                          GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WINDOW_DEINIT, _zapWindow.GetID, 0, 0, GetID, 0, null);
                          _zapWindow.OnMessage(msg);
                          _zapOsdVisible = false;
                          GUIWindowManager.IsOsdVisible = false;
                        }
                        if (_isOsdVisible)
                        {
                          GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WINDOW_DEINIT, _osdWindow.GetID, 0, 0, GetID, 0, null);
                          _osdWindow.OnMessage(msg);
                          _isOsdVisible = false;
                          GUIWindowManager.IsOsdVisible = false;
                        }
                        if (_msnWindowVisible)     // msn related can be removed
                        {
                          GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WINDOW_DEINIT, _msnWindow.GetID, 0, 0, GetID, 0, null);
                          _msnWindow.OnMessage(msg);	// Send a de-init msg to the OSD
                          _msnWindowVisible = false;
                          GUIWindowManager.IsOsdVisible = false;
                        }
                        if (_isDialogVisible && dlg != null)
                        {
                          GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WINDOW_DEINIT, dlg.GetID, 0, 0, GetID, 0, null);
                          dlg.OnMessage(msg);	// Send a de-init msg to the OSD
                        }

                        _bottomDialogMenuVisible = true;
                        _dialogBottomMenu = (GUIDialogMenuBottomRight)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU_BOTTOM_RIGHT);
                        _dialogBottomMenu.TimeOut = 10;
                        _dialogBottomMenu.SetHeading(1004);//About to start recording
                        _dialogBottomMenu.SetHeadingRow2(String.Format("{0} {1}", GUILocalizeStrings.Get(1005), rec.Channel));
                        _dialogBottomMenu.SetHeadingRow3(rec.Title);
                        _dialogBottomMenu.AddLocalizedString(1006); //Allow recording to begin
                        _dialogBottomMenu.AddLocalizedString(1007); //Cancel recording and maintain watching tv
                        _dialogBottomMenu.DoModal(GetID);
                        if (_dialogBottomMenu.SelectedId == 1007) //cancel recording
                        {
                          if (rec.RecType == TVRecording.RecordingType.Once)
                          {
                            rec.Canceled = Utils.datetolong(DateTime.Now);
                          }
                          else
                          {
                            Program prog = message.Object2 as Program;
                            if (prog != null)
                              rec.CanceledSeries.Add(prog.Start);
                            else
                              rec.CanceledSeries.Add(Utils.datetolong(DateTime.Now));
                          }
                          TVDatabase.UpdateRecording(rec, TVDatabase.RecordingChange.Canceled);
                        }
                 */
                _bottomDialogMenuVisible = false;
            }

            #endregion

            #region case GUI_MSG_NOTIFY

            if (message.Message == GUIMessage.MessageType.GUI_MSG_NOTIFY)
            {
                GUIDialogNotify dlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_NOTIFY);
                if (dlgNotify == null)
                {
                    return true;
                }
                string channel = GUIPropertyManager.GetProperty("#TV.View.channel");
                string strLogo = Utils.GetCoverArt(Thumbs.TVChannel, channel);
                dlgNotify.Reset();
                dlgNotify.ClearAll();
                dlgNotify.SetImage(strLogo);
                dlgNotify.SetHeading(channel);
                dlgNotify.SetText(message.Label);
                dlgNotify.TimeOut = message.Param1;
                _notifyDialogVisible = true;
                dlgNotify.DoModal(GUIWindowManager.ActiveWindow);
                _notifyDialogVisible = false;
                Log.Debug("Notify Message:" + channel + ", " + message.Label);
                return true;
            }

            #endregion

            #region case GUI_MSG_TV_ERROR_NOTIFY

            // TEST for TV error handling
            if (message.Message == GUIMessage.MessageType.GUI_MSG_TV_ERROR_NOTIFY)
            {
                UpdateOSD(message.Object);
                return true;
            }

            #endregion

            #region case GUI_MSG_WINDOW_DEINIT

            if (_isOsdVisible)
            {
                if ((message.Message != GUIMessage.MessageType.GUI_MSG_WINDOW_DEINIT))
                {
                    _osdTimeoutTimer = DateTime.Now;
                    // route messages to OSD window
                    if (_osdWindow.OnMessage(message))
                    {
                        return true;
                    }
                }
                else if (message.Param1 == GetID)
                {
                    _osdTimeoutTimer = DateTime.Now;
                    _osdWindow.OnMessage(message);
                }
            }

            #endregion

            switch (message.Message)
            {
                #region case GUI_MSG_HIDE_MESSAGE

                case GUIMessage.MessageType.GUI_MSG_HIDE_MESSAGE:
                    {
                        _messageBoxVisible = false;
                    }
                    break;

                #endregion

                #region case GUI_MSG_SHOW_MESSAGE

                case GUIMessage.MessageType.GUI_MSG_SHOW_MESSAGE:
                    {
                        GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_LABEL_SET, GetID, 0,
                                                        (int)Control.MSG_BOX_LABEL1, 0, 0, null);
                        msg.Label = message.Label;
                        OnMessage(msg);

                        msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_LABEL_SET, GetID, 0, (int)Control.MSG_BOX_LABEL2, 0, 0,
                                             null);
                        msg.Label = message.Label2;
                        OnMessage(msg);

                        msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_LABEL_SET, GetID, 0, (int)Control.MSG_BOX_LABEL3, 0, 0,
                                             null);
                        msg.Label = message.Label3;
                        OnMessage(msg);

                        msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_LABEL_SET, GetID, 0, (int)Control.MSG_BOX_LABEL4, 0, 0,
                                             null);
                        msg.Label = message.Label4;
                        OnMessage(msg);

                        _messageBoxVisible = true;
                        // Set specified timeout
                        _msgBoxTimeout = message.Param1;
                        _msgTimer = DateTime.Now;
                    }
                    break;

                #endregion

                #region case GUI_MSG_WINDOW_DEINIT

                case GUIMessage.MessageType.GUI_MSG_WINDOW_DEINIT:
                    {
                        lock (this)
                        {
                            Log.Debug("TvFullScreen:deinit->OSD:Off");
                            HideMainOSD();

                            _isOsdVisible = false;
                            _isPauseOsdVisible = false;
                            GUIWindowManager.IsOsdVisible = false;
                            GUIWindowManager.IsPauseOsdVisible = false;
                            _channelInputVisible = false;
                            _keyPressedTimer = DateTime.Now;
                            _channelName = "";

                            _stepSeekVisible = false;
                            _statusVisible = false;
                            //_groupVisible = false;
                            _notifyDialogVisible = false;
                            _dialogYesNoVisible = false;
                            _bottomDialogMenuVisible = false;
                            _statusTimeOutTimer = DateTime.Now;

                            _screenState.ContextMenuVisible = false;
                            _screenState.MsgBoxVisible = false;
                            _screenState.OsdVisible = false;
                            _screenState.Paused = false;
                            _screenState.ShowGroup = false;
                            _screenState.ShowInput = false;
                            _screenState.ShowStatusLine = false;
                            _screenState.ShowTime = false;
                            _screenState.ZapOsdVisible = false;
                            _needToClearScreen = false;

                            GUIGraphicsContext.IsFullScreenVideo = false;
                            GUILayerManager.UnRegisterLayer(this);

                            base.OnMessage(message);
                        }
                        return true;
                    }

                #endregion

                #region case GUI_MSG_WINDOW_INIT

                case GUIMessage.MessageType.GUI_MSG_WINDOW_INIT:
                    {
                        base.OnMessage(message);
                        if (!SettingsLoaded)
                            LoadSettings();
                        GUIGraphicsContext.IsFullScreenVideo = true;

                        _osdWindow = (TvOsd)GUIWindowManager.GetWindow((int)Window.WINDOW_TVOSD);
                        _zapWindow = (TvZapOsd)GUIWindowManager.GetWindow((int)Window.WINDOW_TVZAPOSD);

                        _lastPause = g_Player.Paused;
                        _lastSpeed = g_Player.Speed;

                        Log.Debug("TvFullScreen:init->OSD:Off");
                        Log.Debug("TvFullScreen: init, playing {0}, player.CurrentFile {1}", g_Player.Playing, g_Player.CurrentFile);

                        _isOsdVisible = false;
                        GUIWindowManager.IsOsdVisible = false;
                        _channelInputVisible = false;
                        _keyPressedTimer = DateTime.Now;
                        _channelName = "";

                        _isPauseOsdVisible = _lastPause;
                        GUIWindowManager.IsPauseOsdVisible = _lastPause;
                        //_zapTimeOutTimer=DateTime.Now;
                        _osdTimeoutTimer = DateTime.Now;

                        _stepSeekVisible = false;
                        _statusVisible = false;
                        //_groupVisible = false;
                        _notifyDialogVisible = false;
                        _dialogYesNoVisible = false;
                        _bottomDialogMenuVisible = false;
                        _statusTimeOutTimer = DateTime.Now;
                        //imgVolumeBar.Current = VolumeHandler.Instance.Step;
                        //imgVolumeBar.Maximum = VolumeHandler.Instance.StepMax;

                        ResetAllControls(); // make sure the controls are positioned relevant to the OSD Y offset
                        ScreenStateChanged();
                        UpdateGUI();

                        GUIGraphicsContext.IsFullScreenVideo = true;
                        GUILayerManager.RegisterLayer(this, GUILayerManager.LayerType.Osd);

                        RenderVolume(false);

                        //return base.OnMessage(message);
                        return true;
                    }

                #endregion

                #region case GUI_MSG_SETFOCUS

                case GUIMessage.MessageType.GUI_MSG_SETFOCUS:
                    goto case GUIMessage.MessageType.GUI_MSG_LOSTFOCUS;

                #endregion

                #region case GUI_MSG_LOSTFOCUS

                case GUIMessage.MessageType.GUI_MSG_LOSTFOCUS:
                    if (_isOsdVisible)
                    {
                        return true;
                    }
                    if (message.SenderControlId != (int)GUIWindow.Window.WINDOW_TVFULLSCREEN)
                    {
                        return true;
                    }
                    break;

                #endregion
            }
            return base.OnMessage(message);
        }
Exemplo n.º 6
0
        internal static bool RecordProgram(Channel channel, GuideProgram guideProgram, ScheduleType scheduleType, bool NeedConfirm)
        {
            Log.Debug("TVProgammInfo.RecordProgram - channel = {0}, program = {1}", channel.DisplayName, guideProgram.CreateProgramTitle());
            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
            {
                bool hasUpcomingRecording = false;
                bool hasUpcomingAlert = false;

                if (scheduleType == ScheduleType.Recording)
                {
                    UpcomingRecording upcomingRecording;
                    if (HasUpcomingRecording(channel.ChannelId, guideProgram, out upcomingRecording))
                    {
                        hasUpcomingRecording = true;
                        if (upcomingRecording.Program.IsCancelled)
                        {
                            switch (upcomingRecording.Program.CancellationReason)
                            {
                                case UpcomingCancellationReason.Manual:
                                    tvSchedulerAgent.UncancelUpcomingProgram(upcomingRecording.Program.ScheduleId, guideProgram.GuideProgramId, channel.ChannelId, guideProgram.StartTime);
                                    return true;

                                case UpcomingCancellationReason.AlreadyQueued:
                                    {
                                        GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                                        dlg.Reset();
                                        dlg.SetHeading(Utility.GetLocalizedText(TextId.Record));
                                        dlg.SetLine(1, Utility.GetLocalizedText(TextId.ThisProgramIsAlreadyQueued));
                                        dlg.SetLine(2, Utility.GetLocalizedText(TextId.ForRecordingAtAnEarlierTime));
                                        dlg.DoModal(GUIWindowManager.ActiveWindow);
                                    }
                                    break;

                                case UpcomingCancellationReason.PreviouslyRecorded:
                                    {
                                        GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                                        dlg.Reset();
                                        dlg.SetHeading(Utility.GetLocalizedText(TextId.Record));
                                        dlg.SetLine(1, Utility.GetLocalizedText(TextId.ThisProgramWasPreviouslyRecorded));
                                        dlg.DoModal(GUIWindowManager.ActiveWindow);
                                    }
                                    break;
                            }
                        }
                        else
                        {
                            if (upcomingRecording.Program.IsPartOfSeries)
                            {
                                GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                                if (dlg != null)
                                {
                                    dlg.Reset();
                                    dlg.SetHeading(Utility.GetLocalizedText(TextId.DeleteProgram));
                                    dlg.Add(Utility.GetLocalizedText(TextId.CancelThisShow));
                                    dlg.Add(Utility.GetLocalizedText(TextId.DeleteEntireSchedule));
                                    dlg.DoModal(GUIWindowManager.ActiveWindow);

                                    if (dlg.SelectedId > 0)
                                    {
                                        switch (dlg.SelectedLabel)
                                        {
                                            case 0: // Cancel
                                                tvSchedulerAgent.CancelUpcomingProgram(upcomingRecording.Program.ScheduleId,
                                                    guideProgram.GuideProgramId, channel.ChannelId, guideProgram.StartTime);
                                                return true;

                                            case 1: // Delete
                                                Schedule schedule = tvSchedulerAgent.GetScheduleById(upcomingRecording.Program.ScheduleId);
                                                if (schedule != null)
                                                {
                                                    GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                                                    if (dlgYesNo != null)
                                                    {
                                                        dlgYesNo.SetHeading(Utility.GetLocalizedText(TextId.DeleteEntireSchedule));
                                                        dlgYesNo.SetLine(1, "\"" + schedule.Name + "\"");
                                                        dlgYesNo.SetLine(2, Utility.GetLocalizedText(TextId.AreYouSure));
                                                        dlgYesNo.SetLine(3, String.Empty);
                                                        dlgYesNo.SetDefaultToYes(false);
                                                        dlgYesNo.DoModal(GUIWindowManager.ActiveWindow);
                                                        if (dlgYesNo.IsConfirmed)
                                                        {
                                                            tvSchedulerAgent.DeleteSchedule(upcomingRecording.Program.ScheduleId);
                                                            return true;
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (PluginMain.IsActiveRecording(channel.ChannelId, guideProgram))
                                {
                                    GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                                    if (dlgYesNo != null)
                                    {
                                        dlgYesNo.SetHeading(Utility.GetLocalizedText(TextId.StopRecording));
                                        dlgYesNo.SetLine(1, channel.DisplayName);
                                        dlgYesNo.SetLine(2, guideProgram.Title);
                                        dlgYesNo.SetLine(3, string.Empty);
                                        dlgYesNo.SetDefaultToYes(false);
                                        dlgYesNo.DoModal(GUIWindowManager.ActiveWindow);
                                        if (!dlgYesNo.IsConfirmed)
                                        {
                                            return false;
                                        }
                                    }
                                }
                                else if (PluginMain.IsActiveRecording(channel.ChannelId, guideProgram) == false && NeedConfirm)
                                {
                                    GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                                    if (dlgYesNo != null)
                                    {
                                        dlgYesNo.SetHeading(Utility.GetLocalizedText(TextId.DontRecord));
                                        dlgYesNo.SetLine(1, channel.DisplayName);
                                        dlgYesNo.SetLine(2, guideProgram.Title);
                                        dlgYesNo.SetLine(3, string.Empty);
                                        dlgYesNo.SetDefaultToYes(true);
                                        dlgYesNo.DoModal(GUIWindowManager.ActiveWindow);
                                        if (!dlgYesNo.IsConfirmed)
                                        {
                                            return false;
                                        }
                                    }
                                }

                                tvSchedulerAgent.DeleteSchedule(upcomingRecording.Program.ScheduleId);
                                return true;
                            }
                        }
                    }
                }
                else if (scheduleType == ScheduleType.Alert)
                {
                    UpcomingProgram upcomingProgram;
                    if (HasUpcomingProgram(channel.ChannelId, guideProgram, out upcomingProgram, scheduleType))
                    {
                        hasUpcomingAlert = true;
                        if (upcomingProgram.IsCancelled)
                        {
                            switch (upcomingProgram.CancellationReason)
                            {
                                case UpcomingCancellationReason.Manual:
                                    tvSchedulerAgent.UncancelUpcomingProgram(upcomingProgram.ScheduleId, guideProgram.GuideProgramId, channel.ChannelId, guideProgram.StartTime);
                                    return true;

                                case UpcomingCancellationReason.AlreadyQueued:
                                    {
                                        GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                                        dlg.Reset();
                                        dlg.SetHeading(Utility.GetLocalizedText(TextId.Record));
                                        dlg.SetLine(1, Utility.GetLocalizedText(TextId.ThisProgramIsAlreadyQueued));
                                        dlg.SetLine(2, Utility.GetLocalizedText(TextId.ForRecordingAtAnEarlierTime));
                                        dlg.DoModal(GUIWindowManager.ActiveWindow);
                                    }
                                    break;

                                case UpcomingCancellationReason.PreviouslyRecorded:
                                    {
                                        GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                                        dlg.Reset();
                                        dlg.SetHeading(Utility.GetLocalizedText(TextId.Record));
                                        dlg.SetLine(1, Utility.GetLocalizedText(TextId.ThisProgramWasPreviouslyRecorded));
                                        dlg.DoModal(GUIWindowManager.ActiveWindow);
                                    }
                                    break;
                            }
                        }
                        else
                        {
                            if (upcomingProgram.IsPartOfSeries)
                            {
                                GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                                if (dlg != null)
                                {
                                    dlg.Reset();
                                    dlg.SetHeading(Utility.GetLocalizedText(TextId.DeleteProgram));
                                    dlg.Add(Utility.GetLocalizedText(TextId.CancelThisShow));
                                    dlg.Add(Utility.GetLocalizedText(TextId.DeleteEntireSchedule));
                                    dlg.DoModal(GUIWindowManager.ActiveWindow);

                                    if (dlg.SelectedId > 0)
                                    {
                                        switch (dlg.SelectedLabel)
                                        {
                                            case 0: // Cancel
                                                tvSchedulerAgent.CancelUpcomingProgram(upcomingProgram.ScheduleId,
                                                    guideProgram.GuideProgramId, channel.ChannelId, guideProgram.StartTime);
                                                return true;

                                            case 1: // Delete
                                                Schedule schedule = tvSchedulerAgent.GetScheduleById(upcomingProgram.ScheduleId);//GetScheduleById(upcomingRecording.Program.ScheduleId);
                                                if (schedule != null)
                                                {
                                                    GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                                                    if (dlgYesNo != null)
                                                    {
                                                        dlgYesNo.SetHeading(Utility.GetLocalizedText(TextId.DeleteEntireSchedule));
                                                        dlgYesNo.SetLine(1, "\"" + schedule.Name + "\"");
                                                        dlgYesNo.SetLine(2, Utility.GetLocalizedText(TextId.AreYouSure));
                                                        dlgYesNo.SetLine(3, String.Empty);
                                                        dlgYesNo.SetDefaultToYes(false);
                                                        dlgYesNo.DoModal(GUIWindowManager.ActiveWindow);
                                                        if (dlgYesNo.IsConfirmed)
                                                        {
                                                            tvSchedulerAgent.DeleteSchedule(upcomingProgram.ScheduleId);
                                                            return true;
                                                        }
                                                    }
                                                }
                                                break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (NeedConfirm)
                                {
                                    GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                                    if (dlgYesNo != null)
                                    {
                                        dlgYesNo.SetHeading(Utility.GetLocalizedText(TextId.DontRecord));
                                        dlgYesNo.SetLine(1, channel.DisplayName);
                                        dlgYesNo.SetLine(2, guideProgram.Title);
                                        dlgYesNo.SetLine(3, string.Empty);
                                        dlgYesNo.SetDefaultToYes(true);
                                        dlgYesNo.DoModal(GUIWindowManager.ActiveWindow);
                                        if (!dlgYesNo.IsConfirmed)
                                        {
                                            return false;
                                        }
                                    }
                                }
                                tvSchedulerAgent.DeleteSchedule(upcomingProgram.ScheduleId);
                                return true;
                            }
                        }
                    }
                }

                if (!hasUpcomingRecording && !hasUpcomingAlert)
                {
                    GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                    if (dlg != null)
                    {
                        Schedule newSchedule = null;
                        GuideController.RepeatingType dayRepeatingType;

                        dlg.Reset();
                        dlg.SetHeading(Utility.GetLocalizedText(TextId.SelectScheduleType));
                        dlg.Add(Utility.GetLocalizedText(TextId.Once));
                        dlg.Add(Utility.GetLocalizedText(TextId.EverytimeOnThisChannel));
                        dlg.Add(Utility.GetLocalizedText(TextId.EverytimeOnEveryChannel));
                        dlg.Add(Utility.GetLocalizedText(TextId.EveryWeekAtThisTime));
                        dlg.Add(Utility.GetLocalizedText(TextId.EveryDayAtThisTime));
                        if (guideProgram.StartTime.DayOfWeek == DayOfWeek.Saturday
                            || guideProgram.StartTime.DayOfWeek == DayOfWeek.Sunday)
                        {
                            dayRepeatingType = GuideController.RepeatingType.SatSun;
                            dlg.Add(Utility.GetLocalizedText(TextId.SatSun));
                        }
                        else
                        {
                            dayRepeatingType = GuideController.RepeatingType.MonFri;
                            dlg.Add(Utility.GetLocalizedText(TextId.MonFri));
                        }
                        dlg.DoModal(GUIWindowManager.ActiveWindow);

                        switch (dlg.SelectedLabel)
                        {
                            case 0: //once
                                newSchedule = GuideController.CreateRecordOnceSchedule(tvSchedulerAgent, channel.ChannelType, channel.ChannelId,
                                    guideProgram.Title, guideProgram.SubTitle, guideProgram.EpisodeNumberDisplay, guideProgram.StartTime);
                                break;

                            case 1: //everytime, this channel
                                newSchedule = GuideController.CreateRecordRepeatingSchedule(tvSchedulerAgent, GuideController.RepeatingType.AnyTimeThisChannel,
                                    channel.ChannelType, channel.ChannelId, guideProgram.Title, guideProgram.StartTime, "(" + Utility.GetLocalizedText(TextId.AlwaysThisChannel) + ")");
                                ScheduleRule newEpisodesRule = FindNewEpisodesOnlyRule(newSchedule);
                                if (newEpisodesRule != null)
                                {
                                    newEpisodesRule.Arguments[0] = false;
                                }
                                break;

                            case 2: //everytime, any channel
                                newSchedule = GuideController.CreateRecordRepeatingSchedule(tvSchedulerAgent, GuideController.RepeatingType.AnyTime,
                                    channel.ChannelType, null, guideProgram.Title, guideProgram.StartTime, "(" + Utility.GetLocalizedText(TextId.AlwaysEveryChannel) + ")");
                                ScheduleRule newEpisodesRule2 = FindNewEpisodesOnlyRule(newSchedule);
                                if (newEpisodesRule2 != null)
                                {
                                    newEpisodesRule2.Arguments[0] = false;
                                }
                                break;

                            case 3: //weekly
                                newSchedule = GuideController.CreateRecordRepeatingSchedule(tvSchedulerAgent, GuideController.RepeatingType.Weekly,
                                    channel.ChannelType, channel.ChannelId, guideProgram.Title, guideProgram.StartTime, "(" + Utility.GetLocalizedText(TextId.Weekly) + ")");
                                break;

                            case 4: //daily
                                newSchedule = GuideController.CreateRecordRepeatingSchedule(tvSchedulerAgent, GuideController.RepeatingType.Daily,
                                    channel.ChannelType, channel.ChannelId, guideProgram.Title, guideProgram.StartTime, "(" + Utility.GetLocalizedText(TextId.Daily) + ")");
                                break;

                            case 5: //Mon-Fri or Sat-Sun
                                string repeatingTime = string.Empty;
                                if (dayRepeatingType == GuideController.RepeatingType.MonFri)
                                {
                                    repeatingTime = "(" + Utility.GetLocalizedText(TextId.MonFri) + ")";
                                }
                                else if (dayRepeatingType == GuideController.RepeatingType.SatSun)
                                {
                                    repeatingTime = "(" + Utility.GetLocalizedText(TextId.SatSun) + ")";
                                }

                                newSchedule = GuideController.CreateRecordRepeatingSchedule(tvSchedulerAgent, dayRepeatingType,
                                    channel.ChannelType, channel.ChannelId, guideProgram.Title, guideProgram.StartTime, repeatingTime);
                                break;
                        }

                        if (newSchedule != null)
                        {
                            newSchedule.ScheduleType = scheduleType;
                            tvSchedulerAgent.SaveSchedule(newSchedule);
                            return true;
                        }
                    }
                }
                return false;
            }
        }