2 * This file is part of NeverNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
20 package cx.fbn.nevernote.dialog;
\r
23 import com.trolltech.qt.gui.QDialog;
\r
24 import com.trolltech.qt.gui.QGridLayout;
\r
25 import com.trolltech.qt.gui.QLabel;
\r
26 import com.trolltech.qt.gui.QLineEdit;
\r
27 import com.trolltech.qt.gui.QPushButton;
\r
29 public class EnCryptDialog extends QDialog {
\r
31 private boolean okPressed;
\r
32 private final QLineEdit password;
\r
33 private final QLineEdit password2;
\r
34 private final QLineEdit hint;
\r
35 private final QPushButton ok;
\r
36 private final QLabel error;
\r
40 public EnCryptDialog() {
\r
42 setWindowTitle(tr("Encrypt Text"));
\r
43 QGridLayout grid = new QGridLayout();
\r
44 QGridLayout input = new QGridLayout();
\r
45 QGridLayout msgGrid = new QGridLayout();
\r
46 QGridLayout button = new QGridLayout();
\r
50 hint = new QLineEdit("");
\r
51 password = new QLineEdit("");
\r
52 password.setEchoMode(QLineEdit.EchoMode.Password);
\r
53 password2 = new QLineEdit("");
\r
54 password2.setEchoMode(QLineEdit.EchoMode.Password);
\r
57 input.addWidget(new QLabel(tr("Password")), 1,1);
\r
58 input.addWidget(password, 1, 2);
\r
59 input.addWidget(new QLabel(tr("Verify")), 2,1);
\r
60 input.addWidget(password2, 2, 2);
\r
61 input.addWidget(new QLabel(tr("Hint")), 3,1);
\r
62 input.addWidget(hint, 3, 2);
\r
63 input.setContentsMargins(10, 10, -10, -10);
\r
64 grid.addLayout(input, 1,1);
\r
66 error = new QLabel();
\r
67 msgGrid.addWidget(error, 1, 1);
\r
68 grid.addLayout(msgGrid, 2, 1);
\r
70 ok = new QPushButton(tr("OK"));
\r
71 ok.clicked.connect(this, "okButtonPressed()");
\r
72 ok.setEnabled(false);
\r
74 QPushButton cancel = new QPushButton(tr("Cancel"));
\r
75 cancel.clicked.connect(this, "cancelButtonPressed()");
\r
76 button.addWidget(ok, 1, 1);
\r
77 button.addWidget(cancel, 1,2);
\r
78 grid.addLayout(button, 3, 1);
\r
80 password.textChanged.connect(this, "validateInput()");
\r
81 password2.textChanged.connect(this, "validateInput()");
\r
82 hint.textChanged.connect(this, "validateInput()");
\r
86 // The OK button was pressed
\r
87 @SuppressWarnings("unused")
\r
88 private void okButtonPressed() {
\r
92 // The CANCEL button was pressed
\r
93 @SuppressWarnings("unused")
\r
94 private void cancelButtonPressed() {
\r
98 // Get the the validated password from the field
\r
99 public String getPasswordVerify() {
\r
100 return password2.text();
\r
102 // Get the password
\r
103 public String getPassword() {
\r
104 return password.text();
\r
106 // Get the password hint
\r
107 public String getHint() {
\r
108 return hint.text();
\r
110 // Check if the OK button was pressed
\r
111 public boolean okPressed() {
\r
114 // Check if proper input was input
\r
115 @SuppressWarnings("unused")
\r
116 private void validateInput() {
\r
117 ok.setEnabled(false);
\r
119 if (password.text().length()<4) {
\r
120 error.setText(tr("Password must be at least 4 characters"));
\r
123 if (!password.text().equals(password2.text())) {
\r
124 error.setText(tr("Passwords do not match"));
\r
127 if (hint.text().trim().equals("")) {
\r
128 error.setText(tr("Hint must be entered"));
\r
132 ok.setEnabled(true);
\r