[Approved] Patch to enhance TV notification (1 Viewer)

splatterpop

MP Donator
  • Premium Supporter
  • December 17, 2007
    177
    54
    planet ASPARAGUS
    Home Country
    Germany Germany
    A quick update - this procedure works partially:

    + create subclassed dialog object with new() (do not use GetWindow)
    + call Init() to to associate the skin file
    + call SetHeading() - this is mandatory because here AllocResources and InitControls is called (seems weird to me). I did not do this before which is why the dialog was not corrctly initialized.
    + call DoModal()

    The dialog displays now correctly, however it does not to respond to keyboard or mouse interaction.

    Greetings,
    splatterpop
     

    jameson_uk

    Retired Team Member
  • Premium Supporter
  • January 27, 2005
    7,258
    2,528
    Birmingham
    Home Country
    United Kingdom United Kingdom
    Not at a dev machine now but this is a copy and paste job from something I am working on which involves a dialog

    Code:
              GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_YES_NO);
              if (dlgYesNo != null)
              { //setup dialog
                dlgYesNo.SetHeading("Heading");
                dlgYesNo.SetLine(1, "Question");
                dlgYesNo.DoModal(GetID);
                if (dlgYesNo.IsConfirmed)
                { 
                  // handle yes
                }
                else
                {
                  // handle no
                }

    So notice how the dialog is invoked and then GetID (the ID of the window from which dialog is being created) is passed to DoModal. I think what you are missing is adding this dialog to a couple of classes.

    You need to add an entry to the Window enum in GUIWindow.cs (in core project).
    For dialogs you also need to add this value to InputMappingForm(string name) in InputMappingForm.cs (RemotePlugins\InputMapper) to stop the dialog being accessed directly.
    Finally you need to add a localised string for this, string ID is 100000 + the window ID value (eg. I created a new dialog the other day with window ID 512 so string ID was 100512). This gets added to strings_en.xml in MediaPortal.Base\language.

    As I said this I am writing this from memory and not looking at code so might not be 100% but should point you in the right direction.


    Can I suggest you rename your dialog class from TvProgramNotifyDlg to something like GUIDialogTVNotify (not checked what is there now but all dialogs have this naming convention)
     

    splatterpop

    MP Donator
  • Premium Supporter
  • December 17, 2007
    177
    54
    planet ASPARAGUS
    Home Country
    Germany Germany
    Hi jameson,

    thanks but that is basically just what i already did. Well I have to say I did not add a localized string, and I did not touch InputMappingForm. I *believe* for testing purposes that should be sufficient? (Please let me know if it is not.) If so, then the result is just the same - the window does not accept keyboard or mouse input, but closes correctly after the timeout.

    Code:
    TvProgramNotifyDlg dialogNotify2 = (TvProgramNotifyDlg)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TV_NOTIFY);
    dialogNotify2.SetHeading("TV Notification");
    dialogNotify2.SetLine(1, tvProg.Title + " is about to start in " + (tvProg.StartTime - DateTime.Now).Minutes.ToString() + " minutes");
    dialogNotify2.SetLine(2, "Switch to " + tvProg.Channel + " now?");
    dialogNotify2.TimeOut = _notifyTVTimeout;
    if (_playNotifyBeep)
    {
        MediaPortal.Util.Utils.PlaySound("notify.wav", false, true);
    }
    dialogNotify2.DoModal(GUIWindowManager.ActiveWindow);
    riksmith, I found that the window ID enum has nothing to do with the registering/instantiating process. Each public class from each plugin which is a subclass of GUIWindow is being registered, which makes it accessible through GetWindow().

    Let me also point out that, if there are modifications necessary in the core project to implement a subclassed dialog, there is no point in moving it to a plugin. In that case I would prefer adding a timeout to the YesNo dialog, in a backward compatible way.

    Greetings,
    splatterpop
     

    splatterpop

    MP Donator
  • Premium Supporter
  • December 17, 2007
    177
    54
    planet ASPARAGUS
    Home Country
    Germany Germany
    Thanks for the offer. I could not do much since last time. All code changes are documented in this thread. I can also send you the current patch if you prefer.

    Let me know if you need anything else from my side. I would very much like to finish this.

    Kind regards,
    splatterpop
     

    SilentException

    Retired Team Member
  • Premium Supporter
  • October 27, 2008
    2,617
    1,130
    Rijeka, Croatia
    Home Country
    Croatia Croatia
    Hi, sorry for the late reply. I see nothing wrong in the code but I'm also finding it unable to test (since I'm not TVServer developer, I haven't ever debugged it).

    Few notes. I'm not sure why you subclassed dialog in TVLibrary. It would be perfectly good to do these changes (add timeout) to original DialogYesNo. Patch included does that. As for calling the dialog:

    Code:
    GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
    dlgYesNo.Reset();
    dlgYesNo.SetHeading("TV Notification");
    dlgYesN.SetLine(1, tvProg.Title + " is about to start in " + (tvProg.StartTime - DateTime.Now).Minutes.ToString() + " minutes");
    dlgYesN.SetLine(2, "Switch to " + tvProg.Channel + " now?");
    dialogNotify2.TimeOut = 10 // timeout in 10 seconds - you use variable for this
    dlgYesNo.SetDefaultToYes(TRUE/FALSE); // i would recommend false here
    dlgYesNo.DoModal(GUIWindowManager.ActiveWindow);
    if (dlgYesNo.IsConfirmed) ...
    ...

    This should really do the work..

    If it doesn't, you might need to invoke the dialog call:

    Code:
            private delegate bool ShowesNoDialogDelegate(string heading, string lines, bool defaultYes);
    
            public static bool ShowYesNoDialog(string heading, string lines, bool defaultYes)
            {
                if (GUIGraphicsContext.form.InvokeRequired)
                {
                    ShowYesNoDialogDelegate d = ShowYesNoDialog;
                    return (bool)GUIGraphicsContext.form.Invoke(d, heading, lines, defaultYes);
                }
    
                GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                //if (dlgYesNo == null) return;
    
                dlgYesNo.Reset();
                dlgYesNo.SetHeading(heading);
                string[] linesArray = lines.Split(new string[] { "\\n" }, StringSplitOptions.None);
                if (linesArray.Length > 0) dlgYesNo.SetLine(1, linesArray[0]);
                if (linesArray.Length > 1) dlgYesNo.SetLine(2, linesArray[1]);
                if (linesArray.Length > 2) dlgYesNo.SetLine(3, linesArray[2]);
                if (linesArray.Length > 3) dlgYesNo.SetLine(4, linesArray[3]);
                dlgYesNo.SetDefaultToYes(defaultYes);
    
                dlgYesNo.DoModal(GUIWindowManager.ActiveWindow);
                return dlgYesNo.IsConfirmed;
            }
     

    Attachments

    • tvnotifydlg yesno.patch
      1.8 KB

    jameson_uk

    Retired Team Member
  • Premium Supporter
  • January 27, 2005
    7,258
    2,528
    Birmingham
    Home Country
    United Kingdom United Kingdom

    splatterpop

    MP Donator
  • Premium Supporter
  • December 17, 2007
    177
    54
    planet ASPARAGUS
    Home Country
    Germany Germany
    Right that was the idea. That is why the code needs to go to tvplugin. I think it also makes more sense from the architecture perspective.

    In my opinion everything is solved except for the fact that the dialog does not respond for inputs, focus is not set etc. I'm glad to hear that my code looks ok, but then there has to be some more profound reason why the code does not work as expected.
     

    Users who are viewing this thread

    Top Bottom