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.QCheckBox;
\r
24 import com.trolltech.qt.gui.QDialog;
\r
25 import com.trolltech.qt.gui.QGridLayout;
\r
26 import com.trolltech.qt.gui.QLabel;
\r
27 import com.trolltech.qt.gui.QLineEdit;
\r
28 import com.trolltech.qt.gui.QPushButton;
\r
30 public class EnDecryptDialog extends QDialog {
\r
32 private boolean okPressed;
\r
33 private final QLineEdit password;
\r
34 private final QLineEdit password2;
\r
35 private final QLabel hint;
\r
36 private final QPushButton ok;
\r
37 private final QLabel error;
\r
38 private final QCheckBox permanent;
\r
39 private final QCheckBox remember;
\r
43 public EnDecryptDialog() {
\r
45 setWindowTitle(tr("Decrypt Text"));
\r
46 QGridLayout grid = new QGridLayout();
\r
47 QGridLayout input = new QGridLayout();
\r
48 QGridLayout msgGrid = new QGridLayout();
\r
49 QGridLayout button = new QGridLayout();
\r
53 hint = new QLabel("");
\r
54 password = new QLineEdit("");
\r
55 password.setEchoMode(QLineEdit.EchoMode.Password);
\r
56 password2 = new QLineEdit("");
\r
57 password2.setEchoMode(QLineEdit.EchoMode.Password);
\r
60 input.addWidget(new QLabel(tr("Password")), 1,1);
\r
61 input.addWidget(password, 1, 2);
\r
62 input.addWidget(new QLabel(tr("Verify")), 2,1);
\r
63 input.addWidget(password2, 2, 2);
\r
65 permanent = new QCheckBox();
\r
66 permanent.setText(tr("Permanently Decrypt"));
\r
67 input.addWidget(permanent,3,2);
\r
69 remember = new QCheckBox();
\r
70 remember.setText(tr("Remember For This Session"));
\r
71 input.addWidget(remember,4,2);
\r
73 input.setContentsMargins(10, 10, -10, -10);
\r
74 grid.addLayout(input, 1,1);
\r
76 msgGrid.addWidget(new QLabel(tr("Hint: ")), 1,1);
\r
77 msgGrid.addWidget(hint, 1, 2);
\r
78 msgGrid.addWidget(new QLabel(""), 1,3);
\r
79 msgGrid.setColumnStretch(3, 100);
\r
80 error = new QLabel();
\r
81 msgGrid.addWidget(error, 2, 2);
\r
82 grid.addLayout(msgGrid, 2, 1);
\r
84 ok = new QPushButton("OK");
\r
85 ok.clicked.connect(this, "okButtonPressed()");
\r
86 ok.setEnabled(false);
\r
88 QPushButton cancel = new QPushButton(tr("Cancel"));
\r
89 cancel.clicked.connect(this, "cancelButtonPressed()");
\r
90 button.addWidget(ok, 1, 1);
\r
91 button.addWidget(cancel, 1,2);
\r
92 grid.addLayout(button, 3, 1);
\r
94 password.textChanged.connect(this, "validateInput()");
\r
95 password2.textChanged.connect(this, "validateInput()");
\r
98 public boolean permanentlyDecrypt() {
\r
99 return permanent.isChecked();
\r
101 // The OK button was pressed
\r
102 @SuppressWarnings("unused")
\r
103 private void okButtonPressed() {
\r
107 // The CANCEL button was pressed
\r
108 @SuppressWarnings("unused")
\r
109 private void cancelButtonPressed() {
\r
113 // Get the the validated password from the field
\r
114 public String getPasswordVerify() {
\r
115 return password2.text();
\r
117 // Get the password
\r
118 public String getPassword() {
\r
119 return password.text();
\r
121 // Get the password hint
\r
122 public void setHint(String h) {
\r
123 hint.setText(h.replace("'", "'"));
\r
125 // Set the error message
\r
126 public void setError(String e) {
\r
129 // Check if the OK button was pressed
\r
130 public boolean okPressed() {
\r
133 // Check if we should remember the password
\r
134 public boolean rememberPassword() {
\r
135 return remember.isChecked();
\r
137 // Check if proper input was input
\r
138 @SuppressWarnings("unused")
\r
139 private void validateInput() {
\r
140 ok.setEnabled(false);
\r
142 if (!password.text().equals(password2.text())) {
\r
143 error.setText("Passwords do not match");
\r
147 ok.setEnabled(true);
\r