OSDN Git Service

Update merge with local branch. Changes:
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / EnDecryptDialog.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\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
12  *\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
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.dialog;\r
21 \r
22 \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
29 \r
30 public class EnDecryptDialog extends QDialog {\r
31 \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
40         \r
41         \r
42         // Constructor\r
43         public EnDecryptDialog() {\r
44                 okPressed = false;\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
50                 setLayout(grid);\r
51                 \r
52                 \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
58                 \r
59                 \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
64                 \r
65                 permanent = new QCheckBox();\r
66                 permanent.setText(tr("Permanently Decrypt"));\r
67                 input.addWidget(permanent,3,2);\r
68 \r
69                 remember = new QCheckBox();\r
70                 remember.setText(tr("Remember For This Session"));\r
71                 input.addWidget(remember,4,2);\r
72                 \r
73                 input.setContentsMargins(10, 10,  -10, -10);\r
74                 grid.addLayout(input, 1,1);\r
75                 \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
83                 \r
84                 ok = new QPushButton("OK");\r
85                 ok.clicked.connect(this, "okButtonPressed()");\r
86                 ok.setEnabled(false);\r
87                 \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
93                 \r
94                 password.textChanged.connect(this, "validateInput()");\r
95                 password2.textChanged.connect(this, "validateInput()");\r
96                 \r
97         }\r
98         public boolean permanentlyDecrypt() {\r
99                 return permanent.isChecked();\r
100         }\r
101         // The OK button was pressed\r
102         @SuppressWarnings("unused")\r
103         private void okButtonPressed() {\r
104                 okPressed = true;\r
105                 close();\r
106         }\r
107         // The CANCEL button was pressed\r
108         @SuppressWarnings("unused")\r
109         private void cancelButtonPressed() {\r
110                 okPressed = false;\r
111                 close();\r
112         }\r
113         // Get the the validated password from the field\r
114         public String getPasswordVerify() {\r
115                 return password2.text();\r
116         }\r
117         // Get the password \r
118         public String getPassword() {\r
119                 return password.text();\r
120         }\r
121         // Get the password hint\r
122         public void setHint(String h) {\r
123                 hint.setText(h.replace("'", "'"));\r
124         }\r
125         public String getHint() {\r
126                 return hint.text();\r
127         }\r
128         // Set the error message\r
129         public void setError(String e) {\r
130                 error.setText(e);\r
131         }\r
132         // Check if the OK button was pressed\r
133         public boolean okPressed() {\r
134                 return okPressed;\r
135         }\r
136         // Check if we should remember the password\r
137         public boolean rememberPassword() {\r
138                 return remember.isChecked();\r
139         }\r
140         // Check if proper input was input\r
141         @SuppressWarnings("unused")\r
142         private void validateInput() {\r
143                 ok.setEnabled(false);\r
144                 error.setText("");\r
145                 if (!password.text().equals(password2.text())) {\r
146                         error.setText("Passwords do not match");\r
147                         return;\r
148                 }\r
149                 \r
150                 ok.setEnabled(true);\r
151         }\r
152 }\r