Dialog.AskPassword() is a new method that displays a modal dialog box that asks for a user name and a password, and that can remember them.

[GB.FORM.DIALOG]
* NEW: Dialog.AskPassword() is a new method that displays a modal dialog box that asks for a user name and a password, and that can remember them provided that the gb.settings and gb.desktop components are loaded and the Dialog.Key property is set.
* NEW: Dialog.User is a new property that returns the user entered in the ask password dialog.
* NEW: Dialog.Password is a new property that returns the password entered in the ask password dialog.
* NEW: Dialog.NoUser is a new property that tells the ask password dialog not to ask for a user.
This commit is contained in:
gambas 2017-10-10 18:44:00 +02:00
parent 06b5537c2b
commit 3f6569bd06
8 changed files with 258 additions and 11 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

View file

@ -2,7 +2,8 @@
msgid ""
msgstr ""
"Project-Id-Version: gb.form.dialog 3.10.90\n"
"PO-Revision-Date: 2017-09-30 01:41 UTC\n"
"POT-Creation-Date: 2017-10-09 23:09 UTC\n"
"PO-Revision-Date: 2017-10-09 23:08 UTC\n"
"Last-Translator: benoit <benoit@benoit-kubuntu>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
@ -11,13 +12,31 @@ msgstr ""
#: .project:1
msgid "Enhanced standard dialogs"
msgstr ""
msgstr "-"
#: FDirDialog.form:32 FFontDialog.form:35 FInputDate.form:41
#: FAskPassword.form:22
msgid "Authentication"
msgstr "Identification"
#: FAskPassword.form:51
msgid "User"
msgstr "Utilisateur"
#: FAskPassword.form:65
msgid "Password"
msgstr "Mot de passe"
#: FAskPassword.form:78
msgid "Remember password"
msgstr "Se souvenir du mot de passe"
#: FAskPassword.form:98 FDirDialog.form:32 FFontDialog.form:35
#: FInputDate.form:41
msgid "OK"
msgstr "OK"
#: FDirDialog.form:38 FFileDialog.class:107 FFontDialog.form:41 FInputDate.form:47
#: FAskPassword.form:104 FDirDialog.form:38 FFileDialog.class:107
#: FFontDialog.form:41 FInputDate.form:47
msgid "Cancel"
msgstr "Annuler"
@ -26,8 +45,14 @@ msgid "&Overwrite"
msgstr "&Remplacer"
#: FFileDialog.class:107
msgid "This file already exists.\n\nDo you want to overwrite it?"
msgstr "Ce fichier existe déjà.\n\nDésirez-vous le remplacer ?"
msgid ""
"This file already exists.\n"
"\n"
"Do you want to overwrite it?"
msgstr ""
"Ce fichier existe déjà.\n"
"\n"
"Désirez-vous le remplacer ?"
#: FFileDialog.form:22
msgid "Automatic extension"
@ -36,4 +61,3 @@ msgstr "Extension automatique"
#: FFontDialog.form:12
msgid "Select a font"
msgstr "Sélectionnez une police"

View file

@ -7,9 +7,11 @@ VersionFile=1
Component=gb.image
Component=gb.gui
Component=gb.form
Component=gb.desktop.x11
Component=gb.desktop
Component=gb.settings
Authors="Benoît Minisini\nDavid Villalobos Cambronero"
Environment="GB_GUI=gb.gtk3"
Environment="GB_GUI=gb.qt5"
TabSize=2
Translate=1
Language=en

View file

@ -11,6 +11,10 @@ Static Property FixedOnly As Boolean
Static Property Key As String
Static Property User As String
Static Property Read Password As String
Static Property NoUser As Boolean
Static Private $sKey As String
Static Public Function OpenFile(Optional Multi As Boolean) As Boolean
@ -100,3 +104,39 @@ Static Private Sub Key_Write(Value As String)
$sKey = Value
End
Static Public Sub AskPassword() As Boolean
Return FAskPassword.Run()
End
Static Private Function Password_Read() As String
Return FAskPassword.Password
End
Static Private Function NoUser_Read() As Boolean
Return FAskPassword.NoUser
End
Static Private Sub NoUser_Write(Value As Boolean)
FAskPassword.NoUser = Value
End
Static Private Function User_Read() As String
Return FAskPassword.User
End
Static Private Sub User_Write(Value As String)
FAskPassword.User = Value
End

View file

@ -0,0 +1,103 @@
' Gambas class file
Class Desktop
Static Public NoUser As Boolean
Static Public (User) As String
Static Public Password As String
Private $bHasDesktop As Boolean
Private $bHasSettings As Boolean
Private $sKey As String
Public Sub Run() As Boolean
' Dim hWindow As Window
Dim bRet As Integer
Dim iBusy As Integer
' hWindow = New Window
' hWindow.Move(0, 0, Screen.Width, Screen.Height)
' hWindow.Background = Color.Black
' hWindow.Opacity = 40
' hWindow.Border = False
' hWindow.SkipTaskbar = True
' hWindow.Show
iBusy = Application.Busy
Application.Busy = 0
bRet = Not Me.ShowModal()
Application.Busy = iBusy
' hWindow.Close
Return bRet
End
Public Sub btnOK_Click()
{User} = txtUser.Text
Password = txtPassword.Text
If $sKey Then
Settings[$sKey &/ "User"] = txtUser.Text
Settings[$sKey &/ "Remember"] = chkRemember.Value
If $bHasDesktop And If chkRemember.Value Then
Desktop.Passwords[$sKey] = txtPassword.Text
Endif
Endif
Me.Close(True)
End
Public Sub btnCancel_Click()
Me.Close
End
Public Sub Form_Open()
$bHasSettings = Component.IsLoaded("gb.settings")
$bHasDesktop = Component.IsLoaded("gb.desktop")
If Dialog.Title Then Me.Title = Dialog.Title
If $bHasSettings And If Dialog.Key Then $sKey = "gb.form.dialog/FAskPassword/" &/ Dialog.Key
If NoUser Then
txtUser.Enabled = False
Else If $sKey Then
txtUser.Text = Settings[$sKey &/ "User"]
Else
txtUser.Text = {User}
Endif
If $bHasDesktop And If $sKey Then
chkRemember.Show
chkRemember.Value = Settings[$sKey &/ "Remember", False]
If chkRemember.Value Then
txtPassword.Text = Desktop.Passwords[$sKey]
Endif
Else
panPassword.H -= chkRemember.H
Endif
If txtUser.Length Or If NoUser Then
txtPassword.SetFocus
Else
txtUser.SetFocus
Endif
End
Public Sub Form_Close()
NoUser = False
End

View file

@ -0,0 +1,76 @@
# Gambas Form File 3.0
{ Form Form
MoveScaled(0,0,57,21)
Text = ("Authentication")
Icon = Picture["icon:/small/security"]
Resizable = False
Stacking = Window.Above
Arrangement = Arrange.Vertical
AutoResize = True
Spacing = True
Margin = True
{ panPassword HBox
MoveScaled(1,1,52,13)
Spacing = True
{ PictureBox1 PictureBox
MoveScaled(1,1,8,11)
Picture = Picture["icon:/huge/security"]
AutoResize = True
}
{ Panel4 VBox
MoveScaled(9,0,41,13)
Expand = True
Spacing = True
{ HBox2 HBox
MoveScaled(0,0,39,4)
{ Label1 Label
MoveScaled(0,0,13,4)
Text = ("User")
}
{ txtUser TextBox
MoveScaled(21,0,17,4)
Expand = True
}
}
{ HBox3 HBox
MoveScaled(0,5,40,4)
{ Label2 Label
MoveScaled(0,0,13,4)
Text = ("Password")
}
{ txtPassword TextBox
MoveScaled(21,0,17,4)
Expand = True
Password = True
}
}
{ chkRemember CheckBox
MoveScaled(0,9,23,4)
Visible = False
Text = ("Remember password")
}
}
}
{ Panel2 Panel
MoveScaled(20,15,3,1)
}
{ HBox1 HBox
MoveScaled(1,16,51,4)
Spacing = True
{ Panel1 Panel
MoveScaled(3,0,2,4)
Expand = True
}
{ btnOK Button
MoveScaled(11,0,16,4)
Text = ("OK")
Default = True
}
{ btnCancel Button
MoveScaled(30,0,16,4)
Text = ("Cancel")
Cancel = True
}
}
}

View file

@ -2,12 +2,14 @@
Public Sub Main()
' Dialog.Title = "Save document"
Dialog.Filter = ["*.tar.gz", "Archive files", "*.png", "PNG files", "*.jpg;*.jpeg", "JPEG files", "*.bmp", "BMP files"]
Dialog.Title = "Commit"
' Dialog.Filter = ["*.tar.gz", "Archive files", "*.png", "PNG files", "*.jpg;*.jpeg", "JPEG files", "*.bmp", "BMP files"]
' Dialog.AutoExt = True
' If Dialog.SaveFile() Then Return
' Print Dialog.Path
Dialog.OpenFile(True)
Dialog.Key = "test"
Dialog.NoUser = True
Dialog.AskPassword()
End