OSDN Git Service

STAR→Add Star, UNSTAR→Remove Star
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / EnDecryptDialog.java
1 /*\r
2  * This file is part of NixNote/NeighborNote \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 //* decrypt text in a note\r
26 //**********************************************\r
27 //**********************************************\r
28 \r
29 import com.trolltech.qt.gui.QCheckBox;\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 EnDecryptDialog 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 QLabel hint;\r
43         private final QPushButton ok;\r
44         private final QLabel error;\r
45         private final QCheckBox permanent;\r
46         private final QCheckBox remember;\r
47         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
48         \r
49         // Constructor\r
50         public EnDecryptDialog() {\r
51                 okPressed = false;\r
52                 setWindowTitle(tr("Decrypt Text"));\r
53                 setWindowIcon(new QIcon(iconPath+"password.png"));\r
54                 QGridLayout grid = new QGridLayout();\r
55                 QGridLayout input = new QGridLayout();\r
56                 QGridLayout msgGrid = new QGridLayout();\r
57                 QGridLayout button = new QGridLayout();\r
58                 setLayout(grid);\r
59                 \r
60                 \r
61                 hint = new QLabel("");\r
62                 password = new QLineEdit("");\r
63                 password.setEchoMode(QLineEdit.EchoMode.Password);\r
64                 password2 = new QLineEdit("");\r
65                 password2.setEchoMode(QLineEdit.EchoMode.Password);\r
66                 \r
67                 \r
68                 input.addWidget(new QLabel(tr("Password")), 1,1);\r
69                 input.addWidget(password, 1, 2);\r
70                 input.addWidget(new QLabel(tr("Verify")), 2,1);\r
71                 input.addWidget(password2, 2, 2);\r
72                 \r
73                 permanent = new QCheckBox();\r
74                 permanent.setText(tr("Permanently Decrypt"));\r
75                 input.addWidget(permanent,3,2);\r
76 \r
77                 remember = new QCheckBox();\r
78                 remember.setText(tr("Remember For This Session"));\r
79                 input.addWidget(remember,4,2);\r
80                 \r
81                 input.setContentsMargins(10, 10,  -10, -10);\r
82                 grid.addLayout(input, 1,1);\r
83                 \r
84                 msgGrid.addWidget(new QLabel(tr("Hint: ")), 1,1);\r
85                 msgGrid.addWidget(hint, 1, 2);\r
86                 msgGrid.addWidget(new QLabel(""), 1,3);\r
87                 msgGrid.setColumnStretch(3, 100);\r
88                 error = new QLabel();\r
89                 msgGrid.addWidget(error, 2, 2);\r
90                 grid.addLayout(msgGrid, 2, 1);          \r
91                 \r
92                 ok = new QPushButton("OK");\r
93                 ok.clicked.connect(this, "okButtonPressed()");\r
94                 ok.setEnabled(false);\r
95                 \r
96                 QPushButton cancel = new QPushButton(tr("Cancel"));\r
97                 cancel.clicked.connect(this, "cancelButtonPressed()");\r
98                 button.addWidget(ok, 1, 1);\r
99                 button.addWidget(cancel, 1,2);\r
100                 grid.addLayout(button, 3, 1);\r
101                 \r
102                 password.textChanged.connect(this, "validateInput()");\r
103                 password2.textChanged.connect(this, "validateInput()");\r
104                 \r
105         }\r
106         public boolean permanentlyDecrypt() {\r
107                 return permanent.isChecked();\r
108         }\r
109         // The OK button was pressed\r
110         @SuppressWarnings("unused")\r
111         private void okButtonPressed() {\r
112                 okPressed = true;\r
113                 close();\r
114         }\r
115         // The CANCEL button was pressed\r
116         @SuppressWarnings("unused")\r
117         private void cancelButtonPressed() {\r
118                 okPressed = false;\r
119                 close();\r
120         }\r
121         // Get the the validated password from the field\r
122         public String getPasswordVerify() {\r
123                 return password2.text();\r
124         }\r
125         // Get the password \r
126         public String getPassword() {\r
127                 return password.text();\r
128         }\r
129         // Get the password hint\r
130         public void setHint(String h) {\r
131                 hint.setText(h.replace("'", "'"));\r
132         }\r
133         public String getHint() {\r
134                 return hint.text();\r
135         }\r
136         // Set the error message\r
137         public void setError(String e) {\r
138                 error.setText(e);\r
139         }\r
140         // Check if the OK button was pressed\r
141         public boolean okPressed() {\r
142                 return okPressed;\r
143         }\r
144         // Check if we should remember the password\r
145         public boolean rememberPassword() {\r
146                 return remember.isChecked();\r
147         }\r
148         // Check if proper input was input\r
149         @SuppressWarnings("unused")\r
150         private void validateInput() {\r
151                 ok.setEnabled(false);\r
152                 error.setText("");\r
153                 if (!password.text().equals(password2.text())) {\r
154                         error.setText("Passwords do not match");\r
155                         return;\r
156                 }\r
157                 \r
158                 ok.setEnabled(true);\r
159         }\r
160 }\r