2 * This file is part of NixNote
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 //**********************************************
23 //**********************************************
24 //* Chaneg or create a notebook
25 //**********************************************
26 //**********************************************
28 import java.util.List;
30 import com.evernote.edam.type.Notebook;
31 import com.trolltech.qt.gui.QCheckBox;
32 import com.trolltech.qt.gui.QDialog;
33 import com.trolltech.qt.gui.QGridLayout;
34 import com.trolltech.qt.gui.QIcon;
35 import com.trolltech.qt.gui.QLabel;
36 import com.trolltech.qt.gui.QLineEdit;
37 import com.trolltech.qt.gui.QPushButton;
39 public class NotebookEdit extends QDialog {
40 private boolean okPressed;
41 private final QLineEdit notebook;
42 private final QCheckBox localRemote;
43 private final QPushButton ok;
44 private List<Notebook> currentNotebooks;
45 private final QCheckBox isDefault;
46 private boolean startDefault;
47 private String startText;
48 private List<String> stacks;
49 private boolean stackEdit;
50 private final QLabel notebookLabel;
51 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
54 public NotebookEdit() {
57 setWindowTitle(tr("Add Notebook"));
58 setWindowIcon(new QIcon(iconPath+"notebook-green.png"));
59 QGridLayout grid = new QGridLayout();
62 QGridLayout textLayout = new QGridLayout();
63 notebook = new QLineEdit();
64 notebookLabel = new QLabel(tr("Notebook Name"));
65 textLayout.addWidget(notebookLabel, 1,1);
66 textLayout.addWidget(notebook, 1, 2);
67 textLayout.setContentsMargins(10, 10,-10, -10);
68 grid.addLayout(textLayout,1,1);
70 localRemote = new QCheckBox();
71 localRemote.setText(tr("Local Notebook"));
72 localRemote.setChecked(false);
73 grid.addWidget(localRemote, 2,1);
75 isDefault = new QCheckBox();
76 isDefault.setText(tr("Default Notebook"));
77 isDefault.setChecked(false);
78 isDefault.toggled.connect(this, "defaultNotebookChecked(Boolean)");
79 grid.addWidget(isDefault, 3,1);
81 QGridLayout buttonLayout = new QGridLayout();
82 ok = new QPushButton(tr("OK"));
83 ok.clicked.connect(this, "okButtonPressed()");
85 QPushButton cancel = new QPushButton(tr("Cancel"));
86 cancel.clicked.connect(this, "cancelButtonPressed()");
87 notebook.textChanged.connect(this, "textChanged()");
88 buttonLayout.addWidget(ok, 1, 1);
89 buttonLayout.addWidget(cancel, 1,2);
90 grid.addLayout(buttonLayout,4,1);
93 // The OK button was pressed
94 @SuppressWarnings("unused")
95 private void okButtonPressed() {
100 // The CANCEL button was pressed
101 @SuppressWarnings("unused")
102 private void cancelButtonPressed() {
107 // Get the userid from the field
108 public String getNotebook() {
109 return notebook.text();
112 // Set the stack names
113 public void setStacks(List<String> s) {
116 notebookLabel.setText(new String(tr("Stack Name")));
119 // Set the notebook name
120 public void setNotebook(String name) {
121 if (name.equalsIgnoreCase("All Notebooks")) {
122 notebook.setEnabled(false);
123 localRemote.setEnabled(false);
124 isDefault.setEnabled(false);
126 notebook.setText(name);
130 // Is this a local notebook?
131 public boolean isLocal() {
132 return localRemote.isChecked();
135 // Hide the local/remote checkbox
136 public void setLocalCheckboxEnabled(boolean visible) {
137 localRemote.setEnabled(visible);
141 // Check if the OK button was pressed
142 public boolean okPressed() {
146 // Set the window title
147 public void setTitle(String s) {
152 public void setNotebooks(List<Notebook> n) {
153 currentNotebooks = n;
156 // Get default notebook
157 public void setDefaultNotebook(boolean val) {
159 isDefault.setChecked(val);
161 isDefault.setEnabled(true);
163 public boolean isDefaultNotebook() {
164 return isDefault.isChecked();
167 // Action when the default notebook icon is checked
168 @SuppressWarnings("unused")
169 private void defaultNotebookChecked(Boolean val) {
170 if (val != startDefault || !startText.equals(notebook.text()))
173 ok.setEnabled(false);
177 public void hideDefaultCheckbox() {
178 isDefault.setVisible(false);
180 public void hideLocalCheckbox() {
181 localRemote.setVisible(false);
184 // Watch what text is being entered
185 @SuppressWarnings("unused")
186 private void textChanged() {
187 if (notebook.text().equals("")) {
188 ok.setEnabled(false);
191 if (notebook.text().equalsIgnoreCase("All Notebooks")) {
192 ok.setEnabled(false);
196 for (int i=0; i<stacks.size(); i++) {
197 if (stacks.get(i).equalsIgnoreCase(notebook.text())) {
198 ok.setEnabled(false);
204 if (currentNotebooks == null) {
205 ok.setEnabled(false);
208 for (int i=0; i<currentNotebooks.size(); i++) {
209 String s = currentNotebooks.get(i).getName();
210 if (s.equalsIgnoreCase(notebook.text())) {
211 ok.setEnabled(false);