Project

General

Profile

Bug #6105 » ChangePasswordWidget.cpp

Bert Cuypers, 11/16/2017 08:34 AM

 
1
ChangePasswordWidget::ChangePasswordWidget(bool aReqCurrentPsw)
2
	: WDialog(tr("ChangePassword.Title")),
3
	_reqCurrentPsw(aReqCurrentPsw)
4
{
5
	setMovable(false);
6

    
7
	// Contents of dialog => XML defined
8
	WTemplate *formTemplate = contents()->addWidget(std::make_unique<WTemplate>());
9
	formTemplate->addFunction("id", &WTemplate::Functions::id);
10
	formTemplate->addFunction("tr", &WTemplate::Functions::tr);
11
	formTemplate->setCondition("if-reqCurrentPsw", aReqCurrentPsw);
12
	formTemplate->setTemplateText(tr("ChangePasswordWidget"));
13

    
14
	_currentPassword = formTemplate->bindWidget("currentPassword", std::make_unique<WLineEdit>());
15
	_currentPassword->setEchoMode(EchoMode::Password);
16
	_currentPassword->setFocus();
17

    
18
	_newPassword = formTemplate->bindWidget("newPassword", std::make_unique<WLineEdit>());
19
	_newPassword->setEchoMode(EchoMode::Password);
20
	if (aReqCurrentPsw == false)
21
		_newPassword->setFocus();
22
	
23
	_confirmPassword = formTemplate->bindWidget("confirmPassword", std::make_unique<WLineEdit>());
24
	_confirmPassword->setEchoMode(EchoMode::Password);
25
	_confirmPassword->enterPressed().connect(this, &WDialog::accept);
26

    
27
	// Footer of dialog
28
	WPushButton *okButton = footer()->addWidget(std::make_unique<WPushButton>(tr("ChangePassword.UpdateButton")));
29
	okButton->clicked().connect(this, &WDialog::accept);
30
	okButton->setStyleClass("btn btn-primary");
31

    
32
	WPushButton *cancelButton = footer()->addWidget(std::make_unique<WPushButton>(tr("ChangePassword.CancelButton")));
33
	cancelButton->clicked().connect(this, &WDialog::reject);
34
	cancelButton->setStyleClass("btn btn-danger");
35

    
36
	contents()->escapePressed().connect(this, &WDialog::reject);
37
}
38

    
39
ChangePasswordWidget::~ChangePasswordWidget()
40
{
41

    
42
}
43

    
44
bool ChangePasswordWidget::changePassword()
45
{
46
	while (true) {
47
		switch (exec()) {
48
		case DialogCode::Accepted:
49
			// do something
50
			break;
51
		case DialogCode::Rejected:
52
			return false;
53
		}
54
	}
55
}
(1-1/3)