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.QIcon;
29 import com.trolltech.qt.gui.QLabel;
30 import com.trolltech.qt.gui.QLineEdit;
31 import com.trolltech.qt.gui.QPushButton;
33 public class NotebookEdit extends QDialog {
34 private boolean okPressed;
35 private final QLineEdit notebook;
36 private final QCheckBox localRemote;
37 private final QPushButton ok;
38 private List<Notebook> currentNotebooks;
39 private final QCheckBox isDefault;
40 private boolean startDefault;
41 private String startText;
42 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
45 public NotebookEdit() {
47 setWindowTitle(tr("Add Notebook"));
48 setWindowIcon(new QIcon(iconPath+"notebook-green.png"));
49 QGridLayout grid = new QGridLayout();
52 QGridLayout textLayout = new QGridLayout();
53 notebook = new QLineEdit();
54 textLayout.addWidget(new QLabel(tr("Notebook Name")), 1,1);
55 textLayout.addWidget(notebook, 1, 2);
56 textLayout.setContentsMargins(10, 10,-10, -10);
57 grid.addLayout(textLayout,1,1);
59 localRemote = new QCheckBox();
60 localRemote.setText(tr("Local Notebook"));
61 localRemote.setChecked(false);
62 grid.addWidget(localRemote, 2,1);
64 isDefault = new QCheckBox();
65 isDefault.setText(tr("Default Notebook"));
66 isDefault.setChecked(false);
67 isDefault.toggled.connect(this, "defaultNotebookChecked(Boolean)");
68 grid.addWidget(isDefault, 3,1);
70 QGridLayout buttonLayout = new QGridLayout();
71 ok = new QPushButton(tr("OK"));
72 ok.clicked.connect(this, "okButtonPressed()");
74 QPushButton cancel = new QPushButton(tr("Cancel"));
75 cancel.clicked.connect(this, "cancelButtonPressed()");
76 notebook.textChanged.connect(this, "textChanged()");
77 buttonLayout.addWidget(ok, 1, 1);
78 buttonLayout.addWidget(cancel, 1,2);
79 grid.addLayout(buttonLayout,4,1);
82 // The OK button was pressed
83 @SuppressWarnings("unused")
84 private void okButtonPressed() {
89 // The CANCEL button was pressed
90 @SuppressWarnings("unused")
91 private void cancelButtonPressed() {
96 // Get the userid from the field
97 public String getNotebook() {
98 return notebook.text();
101 // Set the notebook name
102 public void setNotebook(String name) {
103 if (name.equalsIgnoreCase("All Notebooks")) {
104 notebook.setEnabled(false);
105 localRemote.setEnabled(false);
106 isDefault.setEnabled(false);
108 notebook.setText(name);
112 // Is this a local notebook?
113 public boolean isLocal() {
114 return localRemote.isChecked();
117 // Hide the local/remote checkbox
118 public void setLocalCheckboxEnabled(boolean visible) {
119 localRemote.setEnabled(visible);
123 // Check if the OK button was pressed
124 public boolean okPressed() {
128 // Set the window title
129 public void setTitle(String s) {
134 public void setNotebooks(List<Notebook> n) {
135 currentNotebooks = n;
138 // Get default notebook
139 public void setDefaultNotebook(boolean val) {
141 isDefault.setChecked(val);
143 isDefault.setEnabled(true);
145 public boolean isDefaultNotebook() {
146 return isDefault.isChecked();
149 // Action when the default notebook icon is checked
150 private void defaultNotebookChecked(Boolean val) {
151 if (val != startDefault || !startText.equals(notebook.text()))
154 ok.setEnabled(false);
157 // Watch what text is being entered
158 @SuppressWarnings("unused")
159 private void textChanged() {
160 if (notebook.text().equals("")) {
161 ok.setEnabled(false);
164 if (notebook.text().equalsIgnoreCase("All Notebooks")) {
165 ok.setEnabled(false);
168 if (currentNotebooks == null) {
169 ok.setEnabled(false);
172 for (int i=0; i<currentNotebooks.size(); i++) {
173 String s = currentNotebooks.get(i).getName();
174 if (s.equalsIgnoreCase(notebook.text())) {
175 ok.setEnabled(false);