OSDN Git Service

Add notebook specific sorting and alter some NeverNote labels to say NixNote.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / EnCryptDialog.java
1 /*\r
2  * This file is part of NixNote \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 //**********************************************\r
24 //* This is the dialog when a user tries to \r
25 //* encrypt text in a note\r
26 //**********************************************\r
27 //**********************************************\r
28 \r
29 \r
30 import com.trolltech.qt.gui.QDialog;\r
31 import com.trolltech.qt.gui.QGridLayout;\r
32 import com.trolltech.qt.gui.QIcon;\r
33 import com.trolltech.qt.gui.QLabel;\r
34 import com.trolltech.qt.gui.QLineEdit;\r
35 import com.trolltech.qt.gui.QPushButton;\r
36 \r
37 public class EnCryptDialog extends QDialog {\r
38 \r
39         private boolean         okPressed;\r
40         private final QLineEdit password;\r
41         private final QLineEdit password2;\r
42         private final QLineEdit hint;\r
43         private final QPushButton ok;\r
44         private final QLabel error;\r
45         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
46         \r
47         \r
48         // Constructor\r
49         public EnCryptDialog() {\r
50                 okPressed = false;\r
51                 setWindowTitle(tr("Encrypt Text"));\r
52                 setWindowIcon(new QIcon(iconPath+"password.png"));\r
53                 QGridLayout grid = new QGridLayout();\r
54                 QGridLayout input = new QGridLayout();\r
55                 QGridLayout msgGrid = new QGridLayout();\r
56                 QGridLayout button = new QGridLayout();\r
57                 setLayout(grid);\r
58                 \r
59                 \r
60                 hint = new QLineEdit("");\r
61                 password = new QLineEdit("");\r
62                 password.setEchoMode(QLineEdit.EchoMode.Password);\r
63                 password2 = new QLineEdit("");\r
64                 password2.setEchoMode(QLineEdit.EchoMode.Password);\r
65                 \r
66                 \r
67                 input.addWidget(new QLabel(tr("Password")), 1,1);\r
68                 input.addWidget(password, 1, 2);\r
69                 input.addWidget(new QLabel(tr("Verify")), 2,1);\r
70                 input.addWidget(password2, 2, 2);\r
71                 input.addWidget(new QLabel(tr("Hint")), 3,1);\r
72                 input.addWidget(hint, 3, 2);\r
73                 input.setContentsMargins(10, 10,  -10, -10);\r
74                 grid.addLayout(input, 1,1);\r
75                 \r
76                 error = new QLabel();\r
77                 msgGrid.addWidget(error, 1, 1);\r
78                 grid.addLayout(msgGrid, 2, 1);\r
79                 \r
80                 ok = new QPushButton(tr("OK"));\r
81                 ok.clicked.connect(this, "okButtonPressed()");\r
82                 ok.setEnabled(false);\r
83                 \r
84                 QPushButton cancel = new QPushButton(tr("Cancel"));\r
85                 cancel.clicked.connect(this, "cancelButtonPressed()");\r
86                 button.addWidget(ok, 1, 1);\r
87                 button.addWidget(cancel, 1,2);\r
88                 grid.addLayout(button, 3, 1);\r
89                 \r
90                 password.textChanged.connect(this, "validateInput()");\r
91                 password2.textChanged.connect(this, "validateInput()");\r
92                 hint.textChanged.connect(this, "validateInput()");\r
93                 \r
94         }\r
95         \r
96         // The OK button was pressed\r
97         @SuppressWarnings("unused")\r
98         private void okButtonPressed() {\r
99                 okPressed = true;\r
100                 close();\r
101         }\r
102         // The CANCEL button was pressed\r
103         @SuppressWarnings("unused")\r
104         private void cancelButtonPressed() {\r
105                 okPressed = false;\r
106                 close();\r
107         }\r
108         // Get the the validated password from the field\r
109         public String getPasswordVerify() {\r
110                 return password2.text();\r
111         }\r
112         // Get the password \r
113         public String getPassword() {\r
114                 return password.text();\r
115         }\r
116         // Get the password hint\r
117         public String getHint() {\r
118                         return hint.text();\r
119         }\r
120         // Check if the OK button was pressed\r
121         public boolean okPressed() {\r
122                 return okPressed;\r
123         }\r
124         // Check if proper input was input\r
125         @SuppressWarnings("unused")\r
126         private void validateInput() {\r
127                 ok.setEnabled(false);\r
128                 error.setText("");\r
129                 if (password.text().length()<4) {\r
130                         error.setText(tr("Password must be at least 4 characters"));\r
131                         return;\r
132                 }\r
133                 if (!password.text().equals(password2.text())) {\r
134                         error.setText(tr("Passwords do not match"));\r
135                         return;\r
136                 }\r
137                 if (hint.text().trim().equals("")) {\r
138                         error.setText(tr("Hint must be entered"));\r
139                         return;\r
140                 }\r
141                 \r
142                 ok.setEnabled(true);\r
143         }\r
144 }\r