/// <summary> /// eventhandler to show CI Menu dialog /// </summary> /// <param name="Menu"></param> protected override void CiMenuCallback(CiMenu Menu) { try { Log.Debug("Callback from tvserver {0}", Menu.Title); // pass menu to calling dialog if (refDlg != null) refDlg.CiMenuCallback(Menu); } catch { Menu = new CiMenu("Remoting Exception", "Communication with server failed", null, TvLibrary.Interfaces.CiMenuState.Error); // pass menu to calling dialog if (refDlg != null) refDlg.CiMenuCallback(Menu); } }
/// <summary> /// Handles all CiMenu actions from callback /// </summary> public static void ShowCiMenu() { lock (CiMenuLock) { if (CiMenuActive || CiMenuList.Count == 0) return; currentCiMenu = CiMenuList[0]; CiMenuList.RemoveAt(0); CiMenuActive = true; // avoid re-entrance from process() } if (dlgCiMenu == null) { dlgCiMenu = (GUIDialogCIMenu) GUIWindowManager.GetWindow((int)MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_DIALOG_CIMENU); } switch (currentCiMenu.State) { // choices available, so show them case TvLibrary.Interfaces.CiMenuState.Ready: dlgCiMenu.Reset(); dlgCiMenu.SetHeading(currentCiMenu.Title, currentCiMenu.Subtitle, currentCiMenu.BottomText); // CI Menu for (int i = 0; i < currentCiMenu.NumChoices; i++) // CI Menu Entries dlgCiMenu.Add(currentCiMenu.MenuEntries[i].Message); // take only message, numbers come from dialog // show dialog and wait for result dlgCiMenu.DoModal(GUIWindowManager.ActiveWindow); if (currentCiMenu.State != TvLibrary.Interfaces.CiMenuState.Error) { if (dlgCiMenu.SelectedId != -1) { TVHome.Card.SelectCiMenu(Convert.ToByte(dlgCiMenu.SelectedId)); } else { if (CiMenuList.Count == 0) // Another menu is pending, do not answer... TVHome.Card.SelectCiMenu(0); // 0 means "back" } } else { TVHome.Card.CloseMenu(); // in case of error close the menu } break; // errors and menu options with no choices case TvLibrary.Interfaces.CiMenuState.Error: case TvLibrary.Interfaces.CiMenuState.NoChoices: if (_dialogNotify == null) { _dialogNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_NOTIFY); } if (null != _dialogNotify) { _dialogNotify.Reset(); _dialogNotify.ClearAll(); _dialogNotify.SetHeading(currentCiMenu.Title); _dialogNotify.SetText(String.Format("{0}\r\n{1}", currentCiMenu.Subtitle, currentCiMenu.BottomText)); _dialogNotify.TimeOut = 2; // seconds _dialogNotify.DoModal(GUIWindowManager.ActiveWindow); } break; // requests require users input so open keyboard case TvLibrary.Interfaces.CiMenuState.Request: String result = ""; if ( GetKeyboard(currentCiMenu.RequestText, currentCiMenu.AnswerLength, currentCiMenu.Password, ref result) == true) { TVHome.Card.SendMenuAnswer(false, result); // send answer, cancel=false } else { TVHome.Card.SendMenuAnswer(true, null); // cancel request } break; case CiMenuState.Close: if (_dialogNotify != null) { GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WINDOW_DEINIT, _dialogNotify.GetID, 0, 0, 0, 0, null); _dialogNotify.OnMessage(msg); // Send a de-init msg to hide the current notify dialog } if (dlgCiMenu != null) { GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WINDOW_DEINIT, dlgCiMenu.GetID, 0, 0, 0, 0, null); dlgCiMenu.OnMessage(msg); // Send a de-init msg to hide the current CI menu dialog } break; } CiMenuActive = false; // finished currentCiMenu = null; // reset menu }
/// <summary> /// Pass the CiMenu to TvHome so that Process can handle it in own thread /// </summary> /// <param name="Menu"></param> public static void ProcessCiMenu(CiMenu Menu) { lock (CiMenuLock) { CiMenuList.Add(Menu); if (CiMenuActive) // Just suppose if a new menu is coming from CAM, last one can be trashed. dlgCiMenu.Reset(); Log.Debug("ProcessCiMenu {0} {1} ", Menu, CiMenuList.Count); } }
/// <summary> /// Client overrides this method to receive the callback events from the server /// </summary> /// <param name="Menu">a CiMenu object</param> protected abstract void CiMenuCallback(CiMenu Menu);
/// <summary> /// [TsWriter Interface Callback] Opens a input request /// </summary> /// <param name="bBlind">?</param> /// <param name="nAnswerLength">expected maximum length of answer</param> /// <param name="lpszText">Title of input</param> /// <returns>0</returns> public int OnCiRequest(bool bBlind, uint nAnswerLength, string lpszText) { if (curMenu == null) { curMenu = new CiMenu(String.Empty, String.Empty, String.Empty, CiMenuState.Request); } curMenu.State = CiMenuState.Request; curMenu.Request(lpszText, (int)nAnswerLength, bBlind); CheckForCallback(); return 0; }
/// <summary> /// Called by the server to fire the call back to the client /// </summary> /// <param name="Menu">a CiMenu object</param> public void FireCiMenuCallback(CiMenu Menu) { //Console.WriteLine("Activating callback"); CiMenuCallback(Menu); }
/// <summary> /// [TsWriter Interface Callback] call to close display /// </summary> /// <param name="nDelay">delay in (ms?)</param> /// <returns>0</returns> public int OnCiCloseDisplay(int nDelay) { // sometimes first a "Close" is sent, even no others callbacks were done before if (curMenu == null) { curMenu = new CiMenu(String.Empty, String.Empty, String.Empty, CiMenuState.Close); } curMenu.State = CiMenuState.Close; CheckForCallback(); return 0; }
/// <summary> /// [TsWriter Interface Callback] Called on initialization of an menu. Options follow in OnCiMenuChoice /// </summary> /// <param name="lpszTitle">Title</param> /// <param name="lpszSubTitle">Subtitle</param> /// <param name="lpszBottom">Bottomtext</param> /// <param name="nNumChoices">number of choices</param> /// <returns>0</returns> public int OnCiMenu(string lpszTitle, string lpszSubTitle, string lpszBottom, int nNumChoices) { curMenu = new CiMenu(lpszTitle, lpszSubTitle, lpszBottom, CiMenuState.Opened); curMenu.NumChoices = nNumChoices; if (nNumChoices == 0) curMenu.State = CiMenuState.NoChoices; CheckForCallback(); return 0; }
/// <summary> /// Handles all CiMenu actions from callback /// </summary> /// <param name="Menu">complete CI menu object</param> public void CiMenuCallback(CiMenu Menu) { ciMenuState = Menu.State; switch (ciMenuState) { // choices available, so show them case TvLibrary.Interfaces.CiMenuState.Ready: //ciMenuState = CiMenuState.Opened; Title.Text = Menu.Title; Subtitle.Text = Menu.Subtitle; BottomText.Text = Menu.BottomText; ciMenuChoices = Menu.NumChoices; Choices.Items.Clear(); // no choices then we are ready yet if (ciMenuChoices == 0) { ciMenuState = CiMenuState.NoChoices; SetButtonState(); } else { foreach (CiMenuEntry entry in Menu.MenuEntries) { Choices.Items.Add(entry); } } break; // errors and menu options with no choices case TvLibrary.Interfaces.CiMenuState.Error: case TvLibrary.Interfaces.CiMenuState.NoChoices: Title.Text = Menu.Title; Subtitle.Text = Menu.Subtitle; BottomText.Text = Menu.BottomText; ciMenuChoices = Menu.NumChoices; break; // requests require users input so open keyboard case TvLibrary.Interfaces.CiMenuState.Request: ciMenuState = CiMenuState.Request; SetButtonState(); CiRequest.Text = String.Format("{0} ({1} Zeichen)", Menu.RequestText, Menu.AnswerLength); CiAnswer.MaxLength = (int)Menu.AnswerLength; CiAnswer.Text = ""; CiAnswer.Focus(); break; } SetButtonState(); }