2 * This file is part of NeverNote
3 * Copyright 2009 Randy Baumgarte
5 * This file may be licensed under the terms of of the
6 * GNU General Public License Version 2 (the ``GPL'').
8 * Software distributed under the License is distributed
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
10 * express or implied. See the GPL for the specific language
11 * governing rights and limitations.
13 * You should have received a copy of the GPL along with this
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
15 * or write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package cx.fbn.nevernote.dialog;
22 import java.util.List;
24 import com.evernote.edam.type.Notebook;
25 import com.trolltech.qt.gui.QCheckBox;
26 import com.trolltech.qt.gui.QDialog;
27 import com.trolltech.qt.gui.QGridLayout;
28 import com.trolltech.qt.gui.QLabel;
29 import com.trolltech.qt.gui.QLineEdit;
30 import com.trolltech.qt.gui.QPushButton;
32 public class NotebookEdit extends QDialog {
33 private boolean okPressed;
34 private final QLineEdit notebook;
35 private final QCheckBox localRemote;
36 private final QPushButton ok;
37 private List<Notebook> currentNotebooks;
40 public NotebookEdit() {
42 setWindowTitle(tr("Add Notebook"));
43 QGridLayout grid = new QGridLayout();
46 QGridLayout textLayout = new QGridLayout();
47 notebook = new QLineEdit();
48 textLayout.addWidget(new QLabel(tr("Notebook Name")), 1,1);
49 textLayout.addWidget(notebook, 1, 2);
50 textLayout.setContentsMargins(10, 10,-10, -10);
51 grid.addLayout(textLayout,1,1);
53 localRemote = new QCheckBox();
54 localRemote.setText(tr("Local Notebook"));
55 localRemote.setChecked(false);
56 grid.addWidget(localRemote, 2,1);
58 QGridLayout buttonLayout = new QGridLayout();
59 ok = new QPushButton(tr("OK"));
60 ok.clicked.connect(this, "okButtonPressed()");
62 QPushButton cancel = new QPushButton(tr("Cancel"));
63 cancel.clicked.connect(this, "cancelButtonPressed()");
64 notebook.textChanged.connect(this, "textChanged()");
65 buttonLayout.addWidget(ok, 1, 1);
66 buttonLayout.addWidget(cancel, 1,2);
67 grid.addLayout(buttonLayout,3,1);
70 // The OK button was pressed
71 @SuppressWarnings("unused")
72 private void okButtonPressed() {
77 // The CANCEL button was pressed
78 @SuppressWarnings("unused")
79 private void cancelButtonPressed() {
84 // Get the userid from the field
85 public String getNotebook() {
86 return notebook.text();
89 // Set the notebook name
90 public void setNotebook(String name) {
91 notebook.setText(name);
94 // Is this a local notebook?
95 public boolean isLocal() {
96 return localRemote.isChecked();
99 // Hide the local/remote checkbox
100 public void setLocalCheckboxEnabled(boolean visible) {
101 localRemote.setEnabled(visible);
105 // Check if the OK button was pressed
106 public boolean okPressed() {
110 // Set the window title
111 public void setTitle(String s) {
116 public void setNotebooks(List<Notebook> n) {
117 currentNotebooks = n;
120 // Watch what text is being entered
121 @SuppressWarnings("unused")
122 private void textChanged() {
123 if (notebook.text().equals("")) {
124 ok.setEnabled(false);
127 if (notebook.text().equalsIgnoreCase("All Notebooks")) {
128 ok.setEnabled(false);
131 if (currentNotebooks == null) {
132 ok.setEnabled(false);
135 for (int i=0; i<currentNotebooks.size(); i++) {
136 String s = currentNotebooks.get(i).getName();
137 if (s.equalsIgnoreCase(notebook.text())) {
138 ok.setEnabled(false);