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.QIcon;
\r
25 import com.trolltech.qt.gui.QLabel;
\r
26 import com.trolltech.qt.gui.QLineEdit;
\r
27 import com.trolltech.qt.gui.QPushButton;
\r
29 import cx.fbn.nevernote.Global;
\r
31 public class LoginDialog extends QDialog {
\r
33 private boolean okPressed;
\r
34 private final QLineEdit userid;
\r
35 private final QLineEdit password;
\r
36 private final QPushButton ok;
\r
37 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
40 public LoginDialog() {
\r
42 setWindowTitle(tr("NeverNote Login"));
\r
43 setWindowIcon(new QIcon(iconPath+"password.png"));
\r
44 QGridLayout grid = new QGridLayout();
\r
46 QGridLayout passwordGrid = new QGridLayout();
\r
47 QGridLayout buttonGrid = new QGridLayout();
\r
49 String useridValue = Global.username;
\r
50 String passwordValue = Global.password;
\r
52 userid = new QLineEdit(useridValue);
\r
53 password = new QLineEdit(passwordValue);
\r
54 password.setEchoMode(QLineEdit.EchoMode.Password);
\r
56 userid.textChanged.connect(this, "validateInput()");
\r
57 password.textChanged.connect(this, "validateInput()");
\r
59 passwordGrid.addWidget(new QLabel(tr("Userid")), 1,1);
\r
60 passwordGrid.addWidget(userid, 1, 2);
\r
61 passwordGrid.addWidget(new QLabel(tr("Password")), 2,1);
\r
62 passwordGrid.addWidget(password, 2, 2);
\r
63 passwordGrid.setContentsMargins(10, 10, -10, -10);
\r
64 grid.addLayout(passwordGrid,1,1);
\r
66 ok = new QPushButton(tr("OK"));
\r
67 ok.clicked.connect(this, "okButtonPressed()");
\r
68 QPushButton cancel = new QPushButton(tr("Cancel"));
\r
69 cancel.clicked.connect(this, "cancelButtonPressed()");
\r
70 buttonGrid.addWidget(ok, 1, 1);
\r
71 buttonGrid.addWidget(cancel, 1,2);
\r
72 grid.addLayout(buttonGrid,2,1);
\r
75 // The OK button was pressed
\r
76 @SuppressWarnings("unused")
\r
77 private void okButtonPressed() {
\r
82 // The CANCEL button was pressed
\r
83 @SuppressWarnings("unused")
\r
84 private void cancelButtonPressed() {
\r
89 // Get the userid from the field
\r
90 public String getUserid() {
\r
91 return userid.text();
\r
94 // Get the password
\r
95 public String getPassword() {
\r
96 return password.text();
\r
99 // Check if the OK button was pressed
\r
100 public boolean okPressed() {
\r
104 // Validate user input
\r
105 public void validateInput() {
\r
106 ok.setEnabled(true);
\r
107 if (userid.text().trim().equals("")) {
\r
108 ok.setEnabled(false);
\r
110 } if (password.text().trim().equals("")) {
\r
111 ok.setEnabled(false);
\r