OSDN Git Service

Remove all .class files from repos
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / DatabaseLoginDialog.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 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
27 \r
28 public class DatabaseLoginDialog extends QDialog {\r
29 \r
30         private boolean         okPressed;\r
31         private final QLineEdit password;\r
32         private final QPushButton ok;\r
33         \r
34         \r
35         // Constructor\r
36         public DatabaseLoginDialog() {\r
37                 okPressed = false;\r
38                 setWindowTitle("Database Password");\r
39                 QGridLayout grid = new QGridLayout();\r
40                 setLayout(grid);\r
41                 QGridLayout passwordGrid = new QGridLayout();\r
42                 QGridLayout buttonGrid = new QGridLayout();\r
43                 \r
44                 String passwordValue = "";\r
45                 \r
46                 password = new QLineEdit(passwordValue);\r
47                 password.setEchoMode(QLineEdit.EchoMode.Password);\r
48                 \r
49                 password.textChanged.connect(this, "validateInput()");\r
50                 \r
51                 passwordGrid.addWidget(new QLabel("Password"), 2,1);\r
52                 passwordGrid.addWidget(password, 2, 2);\r
53                 passwordGrid.setContentsMargins(10, 10,  -10, -10);\r
54                 grid.addLayout(passwordGrid,1,1);\r
55                 \r
56                 ok = new QPushButton("OK");\r
57                 ok.clicked.connect(this, "okButtonPressed()");\r
58                 QPushButton cancel = new QPushButton("Cancel");\r
59                 cancel.clicked.connect(this, "cancelButtonPressed()");\r
60                 buttonGrid.addWidget(ok, 1, 1);\r
61                 buttonGrid.addWidget(cancel, 1,2);\r
62                 grid.addLayout(buttonGrid,2,1);\r
63         }\r
64         \r
65         // The OK button was pressed\r
66         @SuppressWarnings("unused")\r
67         private void okButtonPressed() {\r
68                 okPressed = true;\r
69                 close();\r
70         }\r
71         \r
72         // The CANCEL button was pressed\r
73         @SuppressWarnings("unused")\r
74         private void cancelButtonPressed() {\r
75                 okPressed = false;\r
76                 close();\r
77         }\r
78 \r
79         \r
80         // Get the password \r
81         public String getPassword() {\r
82                 return password.text();\r
83         }\r
84         \r
85         // Check if the OK button was pressed\r
86         public boolean okPressed() {\r
87                 return okPressed;\r
88         }\r
89         \r
90         // Validate user input\r
91         public void validateInput() {\r
92                 ok.setEnabled(true);\r
93                 if (password.text().trim().equals("")) {\r
94                         ok.setEnabled(false);\r
95                         return;\r
96                 }\r
97         }\r
98 }\r