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 List<String> stacks;
43 private boolean stackEdit;
44 private final QLabel notebookLabel;
45 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
48 public NotebookEdit() {
51 setWindowTitle(tr("Add Notebook"));
52 setWindowIcon(new QIcon(iconPath+"notebook-green.png"));
53 QGridLayout grid = new QGridLayout();
56 QGridLayout textLayout = new QGridLayout();
57 notebook = new QLineEdit();
58 notebookLabel = new QLabel(tr("Notebook Name"));
59 textLayout.addWidget(notebookLabel, 1,1);
60 textLayout.addWidget(notebook, 1, 2);
61 textLayout.setContentsMargins(10, 10,-10, -10);
62 grid.addLayout(textLayout,1,1);
64 localRemote = new QCheckBox();
65 localRemote.setText(tr("Local Notebook"));
66 localRemote.setChecked(false);
67 grid.addWidget(localRemote, 2,1);
69 isDefault = new QCheckBox();
70 isDefault.setText(tr("Default Notebook"));
71 isDefault.setChecked(false);
72 isDefault.toggled.connect(this, "defaultNotebookChecked(Boolean)");
73 grid.addWidget(isDefault, 3,1);
75 QGridLayout buttonLayout = new QGridLayout();
76 ok = new QPushButton(tr("OK"));
77 ok.clicked.connect(this, "okButtonPressed()");
79 QPushButton cancel = new QPushButton(tr("Cancel"));
80 cancel.clicked.connect(this, "cancelButtonPressed()");
81 notebook.textChanged.connect(this, "textChanged()");
82 buttonLayout.addWidget(ok, 1, 1);
83 buttonLayout.addWidget(cancel, 1,2);
84 grid.addLayout(buttonLayout,4,1);
87 // The OK button was pressed
88 @SuppressWarnings("unused")
89 private void okButtonPressed() {
94 // The CANCEL button was pressed
95 @SuppressWarnings("unused")
96 private void cancelButtonPressed() {
101 // Get the userid from the field
102 public String getNotebook() {
103 return notebook.text();
106 // Set the stack names
107 public void setStacks(List<String> s) {
110 notebookLabel.setText(new String(tr("Stack Name")));
113 // Set the notebook name
114 public void setNotebook(String name) {
115 if (name.equalsIgnoreCase("All Notebooks")) {
116 notebook.setEnabled(false);
117 localRemote.setEnabled(false);
118 isDefault.setEnabled(false);
120 notebook.setText(name);
124 // Is this a local notebook?
125 public boolean isLocal() {
126 return localRemote.isChecked();
129 // Hide the local/remote checkbox
130 public void setLocalCheckboxEnabled(boolean visible) {
131 localRemote.setEnabled(visible);
135 // Check if the OK button was pressed
136 public boolean okPressed() {
140 // Set the window title
141 public void setTitle(String s) {
146 public void setNotebooks(List<Notebook> n) {
147 currentNotebooks = n;
150 // Get default notebook
151 public void setDefaultNotebook(boolean val) {
153 isDefault.setChecked(val);
155 isDefault.setEnabled(true);
157 public boolean isDefaultNotebook() {
158 return isDefault.isChecked();
161 // Action when the default notebook icon is checked
162 @SuppressWarnings("unused")
163 private void defaultNotebookChecked(Boolean val) {
164 if (val != startDefault || !startText.equals(notebook.text()))
167 ok.setEnabled(false);
171 public void hideDefaultCheckbox() {
172 isDefault.setVisible(false);
174 public void hideLocalCheckbox() {
175 localRemote.setVisible(false);
178 // Watch what text is being entered
179 @SuppressWarnings("unused")
180 private void textChanged() {
181 if (notebook.text().equals("")) {
182 ok.setEnabled(false);
185 if (notebook.text().equalsIgnoreCase("All Notebooks")) {
186 ok.setEnabled(false);
190 for (int i=0; i<stacks.size(); i++) {
191 if (stacks.get(i).equalsIgnoreCase(notebook.text())) {
192 ok.setEnabled(false);
198 if (currentNotebooks == null) {
199 ok.setEnabled(false);
202 for (int i=0; i<currentNotebooks.size(); i++) {
203 String s = currentNotebooks.get(i).getName();
204 if (s.equalsIgnoreCase(notebook.text())) {
205 ok.setEnabled(false);