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 public class DatabaseLoginDialog extends QDialog {
\r
31 private boolean okPressed;
\r
32 private final QLineEdit password;
\r
33 private final QPushButton ok;
\r
34 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
38 public DatabaseLoginDialog() {
\r
40 setWindowTitle(tr("Database Password"));
\r
41 setWindowIcon(new QIcon(iconPath+"password.png"));
\r
42 QGridLayout grid = new QGridLayout();
\r
44 QGridLayout passwordGrid = new QGridLayout();
\r
45 QGridLayout buttonGrid = new QGridLayout();
\r
47 String passwordValue = "";
\r
49 password = new QLineEdit(passwordValue);
\r
50 password.setEchoMode(QLineEdit.EchoMode.Password);
\r
52 password.textChanged.connect(this, "validateInput()");
\r
54 passwordGrid.addWidget(new QLabel(tr("Password")), 2,1);
\r
55 passwordGrid.addWidget(password, 2, 2);
\r
56 passwordGrid.setContentsMargins(10, 10, -10, -10);
\r
57 grid.addLayout(passwordGrid,1,1);
\r
59 ok = new QPushButton(tr("OK"));
\r
60 ok.clicked.connect(this, "okButtonPressed()");
\r
61 QPushButton cancel = new QPushButton(tr("Cancel"));
\r
62 cancel.clicked.connect(this, "cancelButtonPressed()");
\r
63 buttonGrid.addWidget(ok, 1, 1);
\r
64 buttonGrid.addWidget(cancel, 1,2);
\r
65 grid.addLayout(buttonGrid,2,1);
\r
68 // The OK button was pressed
\r
69 @SuppressWarnings("unused")
\r
70 private void okButtonPressed() {
\r
75 // The CANCEL button was pressed
\r
76 @SuppressWarnings("unused")
\r
77 private void cancelButtonPressed() {
\r
83 // Get the password
\r
84 public String getPassword() {
\r
85 return password.text();
\r
88 // Check if the OK button was pressed
\r
89 public boolean okPressed() {
\r
93 // Validate user input
\r
94 public void validateInput() {
\r
95 ok.setEnabled(true);
\r
96 if (password.text().trim().equals("")) {
\r
97 ok.setEnabled(false);
\r