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
22 import com.trolltech.qt.gui.QDialog;
\r
23 import com.trolltech.qt.gui.QGridLayout;
\r
24 import com.trolltech.qt.gui.QLabel;
\r
25 import com.trolltech.qt.gui.QLineEdit;
\r
26 import com.trolltech.qt.gui.QPushButton;
\r
28 public class DBEncryptDialog extends QDialog {
\r
30 private boolean okPressed;
\r
31 private final QLineEdit password1;
\r
32 private final QLineEdit password2;
\r
33 private final QPushButton ok;
\r
37 public DBEncryptDialog() {
\r
39 setWindowTitle(tr("Database Encryption"));
\r
40 QGridLayout grid = new QGridLayout();
\r
42 QGridLayout passwordGrid = new QGridLayout();
\r
43 QGridLayout buttonGrid = new QGridLayout();
\r
45 password1 = new QLineEdit();
\r
46 password1.setEchoMode(QLineEdit.EchoMode.Password);
\r
47 password2 = new QLineEdit();
\r
48 password2.setEchoMode(QLineEdit.EchoMode.Password);
\r
50 password1.textChanged.connect(this, "validateInput()");
\r
51 password2.textChanged.connect(this, "validateInput()");
\r
53 passwordGrid.addWidget(new QLabel(tr("Password")), 1,1);
\r
54 passwordGrid.addWidget(password1, 1, 2);
\r
55 passwordGrid.addWidget(new QLabel(tr("Verify Password")), 2,1);
\r
56 passwordGrid.addWidget(password2, 2, 2);
\r
57 passwordGrid.setContentsMargins(10, 10, -10, -10);
\r
58 grid.addLayout(passwordGrid,1,1);
\r
60 ok = new QPushButton(tr("OK"));
\r
61 ok.setEnabled(false);
\r
62 ok.clicked.connect(this, "okButtonPressed()");
\r
63 QPushButton cancel = new QPushButton(tr("Cancel"));
\r
64 cancel.clicked.connect(this, "cancelButtonPressed()");
\r
65 buttonGrid.addWidget(ok, 1, 1);
\r
66 buttonGrid.addWidget(cancel, 1,2);
\r
67 grid.addLayout(buttonGrid,2,1);
\r
70 // The OK button was pressed
\r
71 @SuppressWarnings("unused")
\r
72 private void okButtonPressed() {
\r
77 // The CANCEL button was pressed
\r
78 @SuppressWarnings("unused")
\r
79 private void cancelButtonPressed() {
\r
84 // Get the userid from the field
\r
85 public String getPassword() {
\r
86 return password1.text();
\r
89 // Check if the OK button was pressed
\r
90 public boolean okPressed() {
\r
94 // Validate user input
\r
95 public void validateInput() {
\r
96 ok.setEnabled(true);
\r
97 if (password1.text().trim().equals("")) {
\r
98 ok.setEnabled(false);
\r
101 if (password1.text().length() < 4) {
\r
102 ok.setEnabled(false);
\r
105 if (!password1.text().equals(password2.text())) {
\r
106 ok.setEnabled(false);
\r