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
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
28 import cx.fbn.nevernote.Global;
\r
30 public class LoginDialog extends QDialog {
\r
32 private boolean okPressed;
\r
33 private final QLineEdit userid;
\r
34 private final QLineEdit password;
\r
35 private final QPushButton ok;
\r
39 public LoginDialog() {
\r
41 setWindowTitle("NeverNote Login");
\r
42 QGridLayout grid = new QGridLayout();
\r
44 QGridLayout passwordGrid = new QGridLayout();
\r
45 QGridLayout buttonGrid = new QGridLayout();
\r
47 String useridValue = Global.username;
\r
48 String passwordValue = Global.password;
\r
50 userid = new QLineEdit(useridValue);
\r
51 password = new QLineEdit(passwordValue);
\r
52 password.setEchoMode(QLineEdit.EchoMode.Password);
\r
54 userid.textChanged.connect(this, "validateInput()");
\r
55 password.textChanged.connect(this, "validateInput()");
\r
57 passwordGrid.addWidget(new QLabel("Userid"), 1,1);
\r
58 passwordGrid.addWidget(userid, 1, 2);
\r
59 passwordGrid.addWidget(new QLabel("Password"), 2,1);
\r
60 passwordGrid.addWidget(password, 2, 2);
\r
61 passwordGrid.setContentsMargins(10, 10, -10, -10);
\r
62 grid.addLayout(passwordGrid,1,1);
\r
64 ok = new QPushButton("OK");
\r
65 ok.clicked.connect(this, "okButtonPressed()");
\r
66 QPushButton cancel = new QPushButton("Cancel");
\r
67 cancel.clicked.connect(this, "cancelButtonPressed()");
\r
68 buttonGrid.addWidget(ok, 1, 1);
\r
69 buttonGrid.addWidget(cancel, 1,2);
\r
70 grid.addLayout(buttonGrid,2,1);
\r
73 // The OK button was pressed
\r
74 @SuppressWarnings("unused")
\r
75 private void okButtonPressed() {
\r
80 // The CANCEL button was pressed
\r
81 @SuppressWarnings("unused")
\r
82 private void cancelButtonPressed() {
\r
87 // Get the userid from the field
\r
88 public String getUserid() {
\r
89 return userid.text();
\r
92 // Get the password
\r
93 public String getPassword() {
\r
94 return password.text();
\r
97 // Check if the OK button was pressed
\r
98 public boolean okPressed() {
\r
102 // Validate user input
\r
103 public void validateInput() {
\r
104 ok.setEnabled(true);
\r
105 if (userid.text().trim().equals("")) {
\r
106 ok.setEnabled(false);
\r
108 } if (password.text().trim().equals("")) {
\r
109 ok.setEnabled(false);
\r