Help me with dialogs an DoModal please (1 Viewer)

pilehave

Community Skin Designer
  • Premium Supporter
  • April 2, 2008
    2,566
    521
    Hornslet
    Home Country
    Denmark Denmark
    Hi

    I want to show a dialog where the user can log in to a web-based service (HeadWeb). This involves a username and password.

    In my main-file (HeadWeb.cs) I open a custom dialog that shows three buttons; "enter username", "enter password" and "login now" which is called when the user pressed a "login" button in the main XML-file:

    HeadWeb.cs

    Code:
          // Check if skin-file for Login dialog exists
          if (System.IO.File.Exists(GUIGraphicsContext.Skin + @"\HeadWebLogin.xml"))
          {
            GUILogin loginDlg = (GUILogin)GUIWindowManager.GetWindow(GUILogin.ID);
    
            // Initialize Dialog
            if (loginDlg != null)
            {
              loginDlg.Reset();
              loginDlg.SetHeading("Login to HeadWeb");
              loginDlg.DoModal(GetID);
            }
          }

    So far so good. The dialog opens, and shows my dialog with the three buttons.

    Now the user is supposed to click "username" and enter his username in the virtual keyboard:

    HeadWebLogin.cs

    Code:
        protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType)
          {
            if (control == btnEnterUsername)
            {
    
              string userNameString = string.Empty;
              GetUserInputString(ref userNameString);
              if (userNameString.Length > 0)
              {
                //Do stuff
                HeadWebSettings.Instance.s_username = userNameString;
              }
    
            }
    
            if (control == btnEnterPassword)
            {
    
              string passwordString = string.Empty;
              GetUserInputString(ref passwordString);
              if (passwordString.Length > 0)
              {
                //Do stuff
                HeadWebSettings.Instance.s_password = passwordString;
              }
    
            }
    
            if (control == btnOK)
            {
              HeadWeb hw = (HeadWeb)GUIWindowManager.GetWindow(HeadWeb.ID);
              HeadWebSettings.Instance.s_cc = new CookieContainer();
              bool loginresult = hw.loginUser(HeadWebSettings.Instance.s_username, HeadWebSettings.Instance.s_password);
              if (loginresult)
              {
                Log.Info("login ok");
                HeadWebSettings.Instance.s_loggedin = true;
              }
              GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WINDOW_DEINIT, GetID, 0, 0, 0, 0, null);
              OnMessage(msg);
              GUIWindowManager.UnRoute();
            }
            base.OnClicked(controlId, control, actionType);
          }

    GetUserInputString() function is a standard virtual keyboard, used many places in MediaPortal:

    Code:
         private bool GetUserInputString(ref string sString)
         {
           VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)Window.WINDOW_VIRTUAL_KEYBOARD);
           if (null == keyboard)
           {
             return false;
           }
           keyboard.IsSearchKeyboard = true;
           keyboard.Reset();
           keyboard.Text = sString;
           keyboard.DoModal(GUIWindowManager.ActiveWindow); // show it...
           if (keyboard.IsConfirmed)
           {
             sString = keyboard.Text;
           }
           return keyboard.IsConfirmed;
         }

    My problem is that when the user has entered some text in the virtual keyboard and presses "enter", the first dialog is not shown any more. Same thing happens if the user cancels the virtual keyboard (Esc).

    Isn't it possible to put a DoModal on top of a DoModal?

    I was looking for this flow:

    Press "Login" button in main GUI
    Login-window with three buttons is shown
    Press "Enter username" button
    Virtual keyboard comes up
    User enters text, and virtual keyboard closes
    Press "Enter pasword" button
    Virtual keyboard comes up
    User enters text, and virtual keyboard closes
    Press "Login"
    User is logged in, and Login-window closes

    I have now tried for several days to crack this :(

    :D
     

    pilehave

    Community Skin Designer
  • Premium Supporter
  • April 2, 2008
    2,566
    521
    Hornslet
    Home Country
    Denmark Denmark
    • Thread starter
    • Moderator
    • #2
    A little dissapointed in the missing feedback, but I fixed it by doing one modal at the time, and closing and opening them one after another. Works ok:
    MEDIAPORTAL - HeadWeb
     

    offbyone

    Development Group
  • Team MediaPortal
  • April 26, 2008
    3,989
    3,712
    Stuttgart
    Home Country
    Germany Germany
    HI
    guess I missed your post - maybe you should check IRC to find more devs :)

    Anyway I think MP only support one modal dialog at a time - i did it basically the same way in Onlinevideos.
     

    pilehave

    Community Skin Designer
  • Premium Supporter
  • April 2, 2008
    2,566
    521
    Hornslet
    Home Country
    Denmark Denmark
    • Thread starter
    • Moderator
    • #4
    HI
    guess I missed your post - maybe you should check IRC to find more devs :)

    Anyway I think MP only support one modal dialog at a time - i did it basically the same way in Onlinevideos.

    Thanks anyways, MP is learning by doing :D
     

    Deda

    Lead Dev MP1 Videos
  • Premium Supporter
  • March 18, 2009
    2,423
    2,385
    Zagreb
    Home Country
    Croatia Croatia
    That was one of the problems which also troubled me (not to enter user/pass but some info about share folders) so I resolved it with simple dialogmenu with 3 items which is in loop (in a way because menu is constantly open after user enter on of the parameter).
     

    SilentException

    Retired Team Member
  • Premium Supporter
  • October 27, 2008
    2,617
    1,130
    Rijeka, Croatia
    Home Country
    Croatia Croatia
    It's not possible to do DoModal on DoModal. New modal window closes current modal window before opening. It's the way it works.

    You need to create new window for this to work as you wish. Or make logic to properly open/close dialogs. For example, in SubCentral, I wanted to do the same - make modify search dialog. But after thinking about it, I realized it wasn't possible. I know Damien had similar troubles with Trakt login dialog / now window.
     

    Users who are viewing this thread

    Top Bottom